Nginx logging to access.log.1 instead of access.log Nginx logging to access.log.1 instead of access.log nginx nginx

Nginx logging to access.log.1 instead of access.log


Solved.

My problem was almost like this but not quite. In that one, the author eventually solved the problem and said the issue 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)." As we've seen, that's not my problem, because my permissions are correct. However, I went and compared my logrotate log with the one on that question, and found something. On that question, the kill signal terminates successfully, but the file handle isn't released by nginx because of permissions. In my case, the invoke-rc.d command does not terminate successfully. The logrotate config for nginx is the following:

/var/log/nginx/*.log {        weekly        missingok        rotate 52        compress        delaycompress        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                invoke-rc.d nginx rotate >/dev/null 2>&1        endscript}

Note the postrotate script, that's the command that tells nginx to do its thing, which for the author on the other thread was the kill signal. In my logrotate log I get the following error (btw you can force logrotate by doing sudo logrotate -f -v /etc/logrotate.d/nginx):

( last two lines ... )running postrotate scripterror: error running shared postrotate script for '/var/log/nginx/*.log '

When I take the postrotate script that you see in the logrotate/nginx config and execute it by hand, it errors:

$ invoke-rc.d nginx rotateinitctl: invalid command: rotateTry `initctl --help' for more information.invoke-rc.d: initscript nginx, action "rotate" failed.

This is a bug in nginx. So what I did was replace that command with the one that the guy on the other thread is using. So now my logrotate/nginx postrotate script on the config file is

postrotate        kill -USR1 `cat /run/nginx.pid`endscript

This solves the issue.


Some more good solution from here

https://unix.stackexchange.com/questions/186807/what-does-nginx-s-reopen-do

So:

postrotate  invoke-rc.d nginx -s reopen >/dev/null 2>&1endscript