控制nginx輸出日誌,設定自動刪除過期日誌
阿新 • • 發佈:2021-05-10
1、檢視nginx執行所用的配置檔案
ps -ef|grep nginx
2、配置nginx輸出內容配置檔案
log_format main "$remote_addr $remote_user [$time_local] '$request_method $host$request_uri'" "$request_time $status $body_bytes_sent '$http_referer'" " '$http_user_agent' '$http_x_forwarded_for'";
3、配置包含多個配置檔案
include /etc/nginx/conf.d/*.conf;
4、檢視系統計劃任務
crontab -l
5、建立指令碼檔案
vim remove_log.sh
#!/bin/bash
#清除nginx日誌檔案
NginxLog_Path=path
#找到.log檔案型別,刪除超過七天的檔案
find ${NginxLog_Path} -type f -name "*.log" -ctime +7 -exec rm -f {} \;
6、加入計劃任務
crontab -e
0 0 * * * path/remove_log.sh