NginX Log Rotation
It has become a sort-of informal semi-standard among Unix daemons that they flush and/or rotate their log files, when you send them a hangup signal (SIGHUP
). Nginx doesn't follow this convention to the letter, but it responds to the USR1
signal the same way, as is documented on the Nginx website under the title Log Rotation.
So, you could try something like
kill -s USR1 `pidof nginx`
logrotating nginx logs:
# nginx SIGUSR1: Re-opens the log files.
/opt/nginx/logs/access.log {
missingok
notifempty
delaycompress
sharedscripts
postrotate
test ! -f /opt/nginx/logs/nginx.pid || kill -USR1 `cat /opt/nginx/logs/nginx.pid`
endscript
}
/opt/nginx/logs/error.log {
missingok
notifempty
delaycompress
sharedscripts
postrotate
test ! -f /opt/nginx/logs/nginx.pid || kill -USR1 `cat /opt/nginx/logs/nginx.pid`
endscript
}
logrotating rails production log:
/home/app_user/apps/railsapp/log/production.log {
missingok
notifempty
delaycompress
sharedscripts
postrotate
test ! -f /opt/nginx/logs/nginx.pid || kill -USR1 `cat /opt/nginx/logs/nginx.pid`
endscript
}
If you use logrotate, add the following (with correct location) into nginx's section of logrotate.conf:
postrotate
kill -s USR1 `cat /location/of/nginx.pid`
endscript
According to logrotate(8) man page