1

I am having issues in nginx log files.

Previously I only made logs to files,

            access_log /var/log/nginx/infotrack_access.log rsyslog;

I added the following file to my /etc/nginx/sites-available/alpha.conf file,

                access_log syslog:server=localhost:514,tag=infotrack rsyslog;

After I added this line, I am having issues that instead of the file infotrack_access.log, the logs are being made in the file infotrack_access.log.1 .

Here is the /etc/logrotate.d/nginx file,

/var/log/nginx/*.log {
    daily
    missingok
    rotate 14
    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
}

When I reload or restart nginx, then for a moment the logs are made to innfotrack_access.log, but after a moment, the logs again go to infotrack_access.log.1

Why is this happening ? I have made no changes in /etc/nginx/nginx.conf file.

How I can solve it ?

1

Run logroate in debug and force mode. logrotate --force -d /etc/logrotate.d/nginx. This will show the error messages in detail. Also check the owners of the log folder.

It might be related to this bug: https://bugs.launchpad.net/nginx/+bug/1450770

  • empty log files are not rotated, old logs are removed, considering log /var/log/nginx/infotrack_access.log ` log does not need rotating` not running prerotate script, since no logs will be rotated not running postrotate script, since no logs were rotated – Luv33preet Aug 16 '17 at 8:09
0

Got the answer in the bug link posted by Tux_DEV_NULL.

Looks like nginx faces some problems post rotation.

So, I needed to make some changes to postrotate section,

 postrotate
        #invoke-rc.d nginx rotate >/dev/null 2>&1
        start-stop-daemon --stop --signal USR1 --quiet --pidfile /run/nginx.pid --name nginx
 endscript

OR for some, this also works,

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.