Nginx的log都是寫在一個文件里的,我需要每天一個Nginx Log網(wǎng)上看到很多辦法,都是寫腳本,定式切割Log文件
2 回答

富國滬深
TA貢獻(xiàn)1790條經(jīng)驗 獲得超9個贊
確認(rèn)cron在運行
service crond status
修改配置文件
vi /etc/crontab
確認(rèn)定時任務(wù)
vi /etc/cron.daily/logrotate
編寫logrotate配置文件 vi /etc/logrotate.d/nginx
/var/log/nginx/*.log { #指定轉(zhuǎn)儲周期為每天 daily missingok #指定日志文件刪除之前轉(zhuǎn)儲的次數(shù),0 指沒有備份,5 指保留5 個備份 rotate 5 #compress #delaycompress #如果是空文件的話,不轉(zhuǎn)儲 notifempty #create 640 root adm sharedscripts postrotate [ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid` endscript }
測試配置
/usr/sbin/logrotate -f /etc/logrotate.d/nginx

守著一只汪
TA貢獻(xiàn)1872條經(jīng)驗 獲得超4個贊
最簡單的辦法就是直接在配置文件中進(jìn)行配置:
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") { set $year $1; set $month $2; set $day $3; } access_log /home/wwwlogs/$year-$month-$day-bbs-access.log access;
- 2 回答
- 0 關(guān)注
- 196 瀏覽
添加回答
舉報
0/150
提交
取消