As you know, when you create a site in nginx webserver, you will want to add custom logs for that site. So this post is a small tip to help you how to do it perfectly.
In your nginx site config (e.g /etx/nginx/site-availables/example.com), you add custom logs as below:
1 2 |
access_log /usr/share/nginx/example.com/nginx-access.log combined; error_log /usr/share/nginx/example.com/nginx-error.log warn; |
So now, your log files will be bigger day by day. You will have to remember to delete the log files if you do not want to your hard disk be full. What should you do now? Fortunately, Logrotate will help you compress. clean and backup it daily.
You just have to add (append) the content below to /etc/logrotate.d/nginx:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/usr/share/nginx/example.com/*.log { daily missingok rotate 52 compress delaycompress copytruncate notifempty create 0640 www-data adm sharedscripts prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi \ endscript postrotate [ -s /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid` endscript } |
Finaly, run the command below to force the update.
1 |
logrotate -f -v /etc/logrotate.d/nginx |
It is done.