CentOS服务器上Nginx日志保存6个月

要配置Nginx以保存超过6个月的日志,您需要定期检查并轮换日志文件。Nginx本身不提供基于时间的日志自动分割功能,但是可以通过logrotate工具或者手动轮换日志文件来实现。 vim /etc/logrotate.d/nginx,没有则创建

# 源文件
/var/log/nginx/*.log {
    create 0640 nginx root
    daily
    rotate 180
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    postrotate
           /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
    endscript
}

修改为

/var/log/nginx/*.log {
    create 0640 nginx root
    daily
    rotate 180
    missingok
    notifempty
    compress
    delaycompress
    sharedscripts
    postrotate
           [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

重启服务:service rsyslog restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章