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:
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:
create 0640 www-data adm
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
[ -s /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid`
Finaly, run the command below to force the update.
logrotate -f -v /etc/logrotate.d/nginx
It is done.