首页 > 技术文章 > Nginx日志按天分割

wangzhigang 2016-03-29 15:27 原文

核心思想:使用crontab在每日23:59执行日志分割。

1、配置nginx日志信息,vim /etc/logrotate.d/nginx

/var/log/nginx/*.log {
    nocompress
    daily
    copytruncate
    create
    notifempty
    rotate 7
    olddir /var/log/nginx
    missingok
    dateext
    postrotate
        /bin/kill -HUP `cat /var/run/nginx.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

2、配置crontab,vim /etc/crontab或者执行crontab -e添加如下信息:

59 23 * * * root ( /usr/sbin/logrotate -f /etc/logrotate.d/nginx)

3、重启cron

service cron restart

 

推荐阅读