Nginx 日志切割,在网上查了很多教程。还不如直接看 Ubuntu / CentOS 打包的 Nginx 日志切割配置靠谱。
CentOS 8
sudo dnf install nginx
cat /etc/logrotate.d/nginx
/var/log/nginx/*log {
create 0664 nginx root
daily
rotate 10
missingok
notifempty
compress
sharedscripts
postrotate
/bin/kill -USR1 cat /run/nginx.pid 2>/dev/null
2>/dev/null || true
endscript
}
Ubuntu 20.10
sudo apt install nginx
cat /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi \
endscript
postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript
}
参考:
https://www.nginx.com/resources/wiki/start/topics/examples/logrotation/
112 total views, 2 views today