Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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