Will Dx

人世一身霜雪, 归来仍是少年.

Nginx使用logrotate切割日志

Posted April 07, 2017

1. 日志路径

Raw
chmod 776 /home/jacky007wang/logs/xingzhe/error.log
chmod 776 /home/jacky007wang/logs/xingzhe/access.log

2. logrotate配置

Python
# vim /etc/logrotate.d/nginx_error

/home/jacky007wang/logs/xingzhe/error.log {
    daily
    rotate 30
    missingok
    dateext
    compress
    delaycompress
    notifempty
    sharedscripts
    postrotate
        kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

# vim /etc/logrotate.d/nginx_access

/home/jacky007wang/logs/xingzhe/access.log {
    daily
    rotate 30
    missingok
    dateext
    compress
    delaycompress
    notifempty
    sharedscripts
    postrotate
        kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

3. 启动

Raw
logrotate -f /etc/logrotate.d/nginx_error
logrotate -f /etc/logrotate.d/nginx_access