1

I have setup individual log files for each of my sites in the directory

/var/log/nginx-hosts/

and I have to configure log rotation for those files. The base I am starting with is

/var/log/nginx-hosts/*.log {
    rotate 7
    daily
    missingok
    notifempty
    sharedscripts
    copytruncate
    compress
}

however, just like apache it appears that nginx has to be shut off pre-rotation in order to actually truncate them. The current nginx logrotate configuration is:

/var/log/nginx/*.log {
        daily
        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
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

should I incorporate the individual site log rotation into the primary or work to figure out the first config in a different file. thoughts? ideas?

thank you for your help and happy holidays.

1 Answer 1

1

after digging further, here is how I fixed this issue:

/var/log/nginx-hosts/*.access{
        weekly
        missingok
        rotate 20
        compress
        dateext
        notifempty
        create 0640 www-data adm
        sharedscripts
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        endscript
}
/var/log/nginx-hosts/*.error{
        weekly
        missingok
        rotate 20
        compress
        dateext
        notifempty
        create 0640 www-data adm
        sharedscripts
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi; \
        endscript
        postrotate
                [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
        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.