日志文件一般存放在 /var/log/nginx 下,若是docker啟動則可以使用主機掛載位置,直接使用 tail -f命令即可查看access日志。
access.log具體每項的含義:
參數(shù) 說明 示例
$remote_addr 客戶端地址 172.17.0.1
$remote_user 客戶端用戶名稱 –
$time_local 訪問時間和時區(qū) [29/Dec/2022:10:17:14 +0000]
$request 請求的URI和http協(xié)議 “GET /test/nginx/proxy http/1.1″
$http_host 請求地址,即瀏覽器中你輸入的地址(IP或域名) 10.1.7.33
$status http請求狀態(tài) 200
$upstream_status upstream狀態(tài) 200
$body_bytes_sent 發(fā)送給客戶端文件內(nèi)容大小 38
$http_referer url跳轉(zhuǎn)來源 – $http_user_agent 用戶終端瀏覽器等信息 “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) chrome/108.0.0.0 Safari/537.36″ $http_cookie 用戶cookie信息 “grafana_session=73d13d456cb4363f8a48f5501348669e”
$ssl_protocol ssl協(xié)議版本 TLSv1
$ssl_cipher 交換數(shù)據(jù)中的算法 RC4-SHA
$upstream_addr 后臺upstream的地址,即真正提供服務的主機地址 “10.1.7.33:8102”
$request_time 整個請求的總時間 0.012
$upstream_response_time 請求過程中,upstream響應時間 0.012
access.log 的格式是可以自己自定義,輸出的信息格式在nginx.conf中設置
可以在location中增加header,輸出用戶代理服務器地址
location /test/ {
#limit_req zone=allips burst=1 nodelay;
proxy_pass http://www.8a.com/test/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
#代理服務器地址
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 8m;
}