Welcome! Log In Create A New Profile

Advanced

Logrotate not working with Nginx

Posted by Lebod 
Logrotate not working with Nginx
August 05, 2015 07:19PM
I've been researching this for a couple of weeks now and have been unable to rectify the problem.
Even on a new Ubuntu 14.0.4 install when you rotate logs, nginx will start giving you permission denied errors for the log files such as:
2015/08/04 22:37:09 [emerg] 23365#0: open() "/var/log/nginx/error.log" failed (13: Permission denied)

After logrotate, you get empty Nginx log files. Log files are really important for me as a system admin.

I've followed the issue here: http://forum.nginx.org/read.php?2,240826,240826#msg-240826 which leads to an issue here: https://bugs.gentoo.org/show_bug.cgi?id=473036

but still can't figure out for the life of me how to fix it...

I know it's a permissions issue somewhere.

My /etc/logrotate.d/nginx file says:

/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
[ -f /run/nginx.pid ] && kill -USR1 `cat /run/nginx.pid`
endscript
}

Any help here would be really appreciated.
Re: Logrotate not working with Nginx
August 06, 2015 05:14AM
Hello,

I don't kown if this will help but I don't use logrotate with nginx.

I use a script scheduled in crontab root who do the job.

The script :

retention=7
log="/applis/nginx/logs"
pid="$log/nginx.pid"

mv $log/access.log $log/access.log.$(date +%Y%m%d)
mv $log/error.log $log/error.log.$(date +%Y%m%d)
kill -USR1 `cat $pid`

find $log/ -type f -name "*.log.*" -mtime +$retention -exec rm -f {} \+
Re: Logrotate not working with Nginx
August 06, 2015 09:53PM
I'd prefer to get logrotate working correctly.
What are the permissions of the files under /var/log/nginx supposed to be ?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 208
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready