centos-rhel服务器相关 / nginx / 未分类 · 2015年4月20日

logrotate管理nginx日志文件–tag

logrotate
1.
[root@b logs]# cat /etc/logrotate.d/nginx
/usr/local/nginx/logs/*log {
daily
rotate 10
missingok
notifempty
compress
sharedscripts
postrotate
if [ -f /usr/local/nginx/nginx.pid ]; then
#/etc/init.d/nginx restart
kill -HSR1 `cat /usr/local/nginx/nginx.pid`

fi
endscript
}
2.crontab
* 4 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx > /dev/null 2>&1
3.nginx 配置文件
server {
listen 80;
server_name a.com;
charset utf-8;
#access_log off;
ccess_log /usr/local/nginx/logs/access.log main;