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

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