Lenmore Blog -- 我的记事本、备忘录

用logrotate截断nginx日志

written on Wednesday, July 2, 2008

logrotate参考:http://www.linuxcommand.org/man_pages/logrotate8.html

apache也是用logrotate来截断并压缩日志的,参考了一下,有了下面的脚本,并且保存到 /etc/logrotate.d/nginx:

/srv/www/logs/blog/access.log {
daily
missingok
rotate 7
nocompress
sharedscripts
postrotate
/etc/init.d/nginx restart >/dev/null
endscript
}

参数的具体含义请看参考或这 man logrotate

效果很好,加上 dateext 参数还能加上当前日期后缀

另外,nginx支持 USR1 信号来重新打开日志文件

sudo kill -USR1 `cat /var/run/nginx.pid`

This entry was tagged logrotate and nginx