linux_Nginx日志
錯誤信息日志配置:
日志文件默認:/application/nginx/logs/erroe.log
?????? error_log logs/error.log error;?
# 不寫默認就有,默認error,這個不要配置成info,數據庫錯誤日志不要配置成info,做反向代理或者web服務,一定不要給info,帶來巨大的磁盤IO消耗
?Nginx日志變量說明
?????? $remote_addr???????????? ????????????? 記錄訪問網站的客戶端
?????? $http_x_forwarded_for ??????????? 當前代理服務器時,設置web節點記錄客戶端地址的配置
?????? $remote_user?????????????????????????? 遠程客戶端用戶名
?????? $time_local?????????????????????????????? 記錄訪問時間與時區
?????? $request?????????????????????????????????? 用戶的http請求起始行信息
?????? $status????????????????????????????????????? http狀態碼,記錄請求返回的狀態碼
?????? $body_bytes_sents????????????????? 服務器發送給客戶端的相應body字節數
?????? $http_referer??????????????????????????? 記錄此次請求是從那個鏈接訪問過來的
?????? $http_user_agent???????????????????? 記錄訪問客戶端信息
?????? # 這些參數,如果沒有數據,將默認為 -
在Nginx主配置文件nginx.conf中http模塊中寫入,long_format字段,添加日志格,定義日志全局格式
log_format main '$remote_addr - $remote_user [$time_local] "$request"''$status $body_bytes_sent "$http_referer"''"$http_user_agent "$http_x_forwarded_for"';然后在每個server中,添加 access_log 字段,為每個單獨的server添加訪問日志
access_log logs/www_access.log main;?????? 這個access_log 參數最后還可以添加buffer 和 flush參數,格式為:
????????????? access_log path format [buffer=size] [flush=time] [if=condition]
# 緩存多大時候寫一次日志,或者間隔多長時間寫一次日志,if=condition 是固定寫法,滿足條件的意思,增加IO性能,在高并發的情況下提升網絡訪問性能
Nginx日志切割
?????? 通過 .sh + crond 來進行日志切割,通過rsync進行日志備份,通過find刪除180天以前的日志
mkdir /server/scripts -p # 創建一個寫腳本的目錄,規范 cd /server/scripts/ # 切換到目錄下 vim cut_nginx_log.sh # 編輯一個腳本,注意腳本名,規范,見名知意 cd /application/nginx/logs && \/bin/mv www_access.log www_access_$(date +%F -d '-1day').log && \/application/nginx/sbin/nginx -s reload && \find /application/nginx/logs/ -type f -name www_access_*.log -mtime +7|xargs rm -f && \rsync -avz /application/nginx/logs/ rsync_backup@172.16.1.41::nginxlog --password-file=/etc/rsync.passwordsh -x cut_nginx_log.sh # 測試 crontab -e # 寫入定時任務 00 00 * * * /bin/bash /server/scripts/cut_nginx_log.sh > /dev/null 2>&1# 備份任務都是晚上凌晨以后,如果有必要,需要進行 --bwlimit= 進行限速,單位為k?
轉載于:https://www.cnblogs.com/2bjiujiu/p/8117395.html
總結
以上是生活随笔為你收集整理的linux_Nginx日志的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: nprogress.js 头部进度条使用
- 下一篇: 在windows平台使用Apache J