nginx日誌格式案例

###nginx日誌格式案例(一)html

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';
  • $remote_addr: 客戶端IP地址
  • $remote_user: 爲基本用戶認證提供的用戶名
  • $time_local: 通用日誌格式下的本地時間
  • $request: 完整的原始請求行(in ngx_http_core_module)
  • $status: 響應碼
  • $body_bytes_sent : nginx返回給客戶端的字節數,不含響應頭
  • $http_referer:
  • $http_user_agent: 記錄客戶端瀏覽器相關信息
  • $http_x_forwarded_for: 獲取真實IP地址
【ngx_http_proxy_module中】
$proxy_add_x_forwarded_for
將$remote_addr變量值添加在客戶端「X-Forwarded-For」請求頭的後面,並以逗號分隔。 若是客戶端請求未攜帶「X-Forwarded-For」請求頭,$proxy_add_x_forwarded_for變量值將與$remote_addr變量相同。

###nginx日誌格式案例(二)nginx

log_format main '$host ' //「Host」請求頭的值,若是沒有該請求頭,則爲與請求對應的虛擬主機的首要主機名
                    '$server_addr ' //接受請求的服務器地址
                    '$remote_addr ' //客戶端IP地址
                    '- '
                    '"$time_local" ' 
                    '$status '
                    '$body_bytes_sent ' 
                    '$request_time ' //請求處理的時間,單位爲秒,精度是毫秒(1.3.9, 1.2.6);請求處理時間從由客戶端接收到第一個字節開始計算
                    '"$http_referer" ' //告訴服務器我是從哪一個頁面連接過來的
                    '"$request" '
                    '"$http_user_agent" '
                    '$pid'; //處理請求的nginx進程id

參考1瀏覽器

相關文章
相關標籤/搜索