nginx logging to access.log.1 instead of access.log, logrotate failing?

Solution 1:

Bah, I finally found the answer after a long time digging. The problem, in my case wasn't that logrotate was failing. That error message is fine, and doesn't actually stop logrotate. The problem was that nginx was not releasing the file handle to the log file upon receiving the -USR1 signal from kill. Long story short, the reason it was not reloading the log files was because the /var/log/nginx folder was not owned by the same user as the nginx worker processes (owned by www-data, running under web). I have no idea how that changed (perhaps because this server was remade recently), but changing the folder to be owned by the same user as the nginx worker processes (and fixing the logrotate file to make new logs as web) fixed the issue.

Solution 2:

I have the same problem in Ubuntu 14.04, but after reading your answer, I checked that my nginx is running under www-data, who owns the folder, so...

However, I have found this bug, which points on the mistake in the postrotate section in the /etc/logrotate.d/nginx.

To fix it, you could comment out

invoke-rc.d nginx rotate >/dev/null 2>&1

and the use any of the following options (from comments in that bug) instead:

  • start-stop-daemon --stop --signal USR1 --quiet --pidfile /run/nginx.pid --name nginx
  • nginx -s reload
  • service nginx reload >/dev/null 2>&1