Home » Linux » 通过logrotate使Nginx每天生成一个日志文件并压缩

1、vi /etc/logrotate.d/nginx

/var/log/nginx/*.log{
daily //轮转周期,每天
compress //压缩
rotate 365 //保留多少个日志文件
missingok //日志文件丢失,不提示错误
notifempty //为空的日志文件不执行
dateext //以当前日期位文件名后缀,比如access.log-yyyy-mm-dd.gz
sharedscripts //运行脚本
postrotate
 /bin/kill -HUP `cat /run/nginx.pid 2> /dev/null` 2> /dev/null || true
endscript //结束
}

2、添加计划任务

59 23 * * * root /usr/sbin/logrotate -f /etc/logrotate.d/nginx

==================

出错:

error: skipping "/var/log/nginx/access.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

解决:

chmod -R 755 /var/log/nginx

标签: Nginx logrotate 日志切割 每日一个日志文件

添加新评论

V