Linux下nginx生成日志自動切割的實現方法
更新時間:2017年10月20日 15:33:37 作者:神神的蝸牛
這篇文章主要介紹了 Linux下nginx生成日志自動切割的實現方法的相關資料,希望通過本文能幫助到大家,讓大家實現這樣的功能看,需要的朋友可以參考下
Linux下nginx生成日志自動切割的實現方法
1、編輯切割日志的 shell 程序,目錄自定
#vi /data/nginx/cut_nginx_log.sh
輸入代碼:
#!/bin/bash # This script run at 00:00 function cutAccess() { dir=$1 newdir="${dir}/$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")" suffix=$(date -d "yesterday" +"%Y%m%d") mkdir -p $newdir mv ${dir}/access.log ${newdir}/access.$suffix.log } cutAccess "/home/wwwlogs/www.yourdomain.com/" cutAccess "/home/wwwlogs/www.yourdomain-1.com/" cutAccess "/home/wwwlogs/www.yourdomain-2.com/" # 重啟 nginx kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
2、加入定時任務,每天0點自動切割
# crontab -e 0 0 * * * /bin/bash /data/nginx/cut_nginx_log.sh
3、nginx 日志格式
log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log /home/wwwlogs/www.yourdomain.com/access.log access;
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
解決ubuntu安裝軟件時,status-code=409報錯的問題
這篇文章主要介紹了解決ubuntu安裝軟件時,status-code=409報錯的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12