nginx如何做日志切割
Nginx的log都是写在一个文件里的,我需要每天一个Nginx Log
网上看到很多办法,都是写脚本,定式切割Log文件
Nginx自己不能做日志切割这件事吗?
Answers
确认cron在运行
service crond status
修改配置文件
vi /etc/crontab
确认定时任务
vi /etc/cron.daily/logrotate
编写logrotate配置文件 vi /etc/logrotate.d/nginx
/var/log/nginx/*.log {
#指定转储周期为每天
daily
missingok
#指定日志文件删除之前转储的次数,0 指没有备份,5 指保留5 个备份
rotate 5
#compress
#delaycompress
#如果是空文件的话,不转储
notifempty
#create 640 root adm
sharedscripts
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
endscript
}
测试配置
/usr/sbin/logrotate -f /etc/logrotate.d/nginx