Nginx日志按天分割

核心思想:使用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
原文地址:https://www.cnblogs.com/wangzhigang/p/5333132.html