MR.ASONG

Nginx 日志自动切割

2016/12/23 594 1
cd  /etc/logrotate.d 

vi /etc/logrotate.d/nginx 

/home/wwwlogs/*.log {
    missingok
    dateext
    notifempty
    daily
    rotate 7
    sharedscripts
    postrotate
    if [ -f /usr/local/nginx/logs/nginx.pid ]; then
        kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
    fi
    endscript
}

:wq!  #保存退出

mkdir -p  /usr/local/nginx/logs/nginx_logs/
chmod +x  /etc/logrotate.d/nginx  #添加执行权限
/usr/sbin/logrotate -vf  /etc/logrotate.d/nginx

crontab  -e  #添加以下代码
0 0 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/nginx  #每天凌晨定时执行脚本

添加新评论