ngx_http_log_module 模塊負責日誌:前端
=======默認nginx日誌linux
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
效果1:
192.168.11.12 - - [01/Feb/2018:10:12:05 +0800] "HEAD /ss HTTP/1.1" 200 0 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"nginx
========自定義nginx日誌
log_format access '$remote_addr - "$host" "$hostname" [$time_local] '
'"$request" $status $bytes_sent $body_bytes_sent $request_time '
'"$http_referer" "$http_user_agent" $server_addr '
'"$http_range" $upstream_response_time "$upstream_addr" $upstream_status $upstream_http_Isure_Upstream_Time';
效果1:
192.168.11.12 - "www.web2.com" "dev-2" [01/Feb/2018:10:36:54 +0800] "GET /ss/gskhsk HTTP/1.1" 200 235 39 0.001 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2" 192.168.11.12 "-" 0.001 "127.0.0.1:9000" 200 -web
效果2:
192.168.11.188 - "www.web2.com" "dev-2" [01/Feb/2018:10:40:42 +0800] "GET http://www.web2.com/ss/gskhsk HTTP/1.1" 200 235 39 0.001 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2" 192.168.11.12 "-" 0.001 "127.0.0.1:9000" 200 -瀏覽器
配置:
access_log /logs/nginx/access.log access;服務器
log_format格式變量:ssh
$remote_addr #記錄訪問網站的客戶端地址 $remote_user #遠程客戶端用戶名 $time_local #記錄訪問時間與時區 $request #用戶的http請求起始行信息 $status #http狀態碼,記錄請求返回的狀態碼,例如:200、30一、404等 $body_bytes_sent #服務器發送給客戶端的響應body字節數 $http_referer #記錄這次請求是從哪一個鏈接訪問過來的,能夠根據該參數進行防盜鏈設置。 $http_user_agent #記錄客戶端訪問信息,例如:瀏覽器、手機客戶端等 $http_x_forwarded_for #當前端有代理服務器時,設置web節點記錄客戶端地址的配置,此參數生效的前提是代理服務器也要進行相關的x_forwarded_for設置
測試: curl -I "http://web2.com?name=yeqing&age=18" -x 192.168.11.12:80curl
注意:自定義完日誌 須要 service nginx restartide