Skip to content

Instantly share code, notes, and snippets.

@safecat
Last active May 10, 2016 16:00
Show Gist options
  • Save safecat/e3764e1eb670a05f3f0e to your computer and use it in GitHub Desktop.
Save safecat/e3764e1eb670a05f3f0e to your computer and use it in GitHub Desktop.
Nginx log rotate
# 日志切割时间
vi /etc/crontab
# 把cron.daily的时间改为0 0
# 日志切割文件存储格式
vi /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress #重要
dateformat %Y%m%d. #重要
dateext #重要
extension log #文件扩展名
notifempty
create 0640 deploy deploy #重要
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \
endscript
postrotate
[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`
endscript
}
# 调试命令
sudo /usr/sbin/logrotate --force /etc/logrotate.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment