I have a logrotate task to rotate my nginx logs. I have my config file in /etc/logrotate.d/nginx. When I run logrotate -f /etc/logrotate.d/nginx
, it can rotate the logs correctly, which means my config file is corrent.
By when I put the command in cron like 0 0 * * * logrotate -f /etc/logrotate.d/nginx
, the logs are not rotated. Although I can see CRON[6006]: (root) CMD (logrotate -f /etc/logrotate.d/nginx)
in /var/log/cron.log, which means the command does have been run. Is there anything wrong?
Here's my logrotate config file:
/var/log/nginx/access.log {
daily
rotate 3
compress
copytruncate
dateext
}
/var/log/nginx/error.log {
daily
rotate 7
compress
copytruncate
dateext
}