日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Nginx日志优化

發布時間:2023/10/18 95 如意码农
生活随笔 收集整理的這篇文章主要介紹了 Nginx日志优化 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一 日志輪訓切割

[root@centos7 tools]# cat nginx_log.sh
#!/bin/bash cd /var/log/nginx/ &&\
/bin/mv access.log access_%(date +%F -d -1day).log
systemctl reload nginx

二 不記錄不需要的訪問日志

        location ~.*\.(js|jpg|JPG|JPEG|css|bmp|gif|GIF)% {
access_log off;
}

三 修改日志格式為json格式

http {
include mime.types;
default_type application/octet-stream; log_format access_json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"domain":"$host",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"status":"$status"}';
access_log /var/log/nginx/access_json.log access_json;
host":"$server_addr:服務端地址
clientip":"$remote_addr: 記錄客戶端IP地址
size":$body_bytes_sent:  發送給客戶端的字節數,不包括響應頭的大小
responsetime":$request_time:請求處理時間,單位為秒 從客戶端請求到寫入日志時間
upstreamtime":"$upstream_response_time:指從Nginx向后端(php-cgi)建立連接開始到接受完數據然后關閉連接為止的時間。
upstreamhost":"$upstream_addr:upstream :屬于handler,只是他不產生自己的內容,而是通過請求后端服務器得到內容
http_host":"$host:
url":"$uri:
domain":"$host:
xff":"$http_x_forwarded_for:
referer":"$http_referer: 記錄從哪個頁面鏈接訪問過來的
status":"$status:記錄請求狀態碼



                            

總結

以上是生活随笔為你收集整理的Nginx日志优化的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。