Nginx 中的很多引數可以使用內置的變數來設定,本文主要介紹一些常用的變數,
1、Nginx 組態檔中變數使用
http { ... log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; ... server { listen 8089; server_name localhost; location /abc { proxy_pass http://10.39.196.30:8080/abc; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; ... } ...
在該組態檔中使用多個變數來定義日期格式(log_format),并使用變數來設定傳遞給代理服務器的請求頭(proxy_set_header),
2、常用變數說明
| 變數 | 說明 |
| $arg_name | 表示請求行中的任意引數,name 為引數名稱 |
| $args | 表示請求行中的引數部分 |
| $binary_remote_addr | 二進制形式表示的客戶端地址 |
| $body_bytes_sent | 發送到客戶端的位元組數,不包括回應頭 |
| $bytes_received | 接受到客戶端的位元組數 |
| $bytes_sent | 發送到客戶端的位元組數 |
| $connection | 連接序列號 |
| $connection_requests | 當前連接的請求數量 |
| $connection_time | 連接時間,單位為:ms |
| $cookie_name | 表示任意 cookie,name 為 cookie 名稱 |
| $date_gmt | GMT 時間 |
| $date_local | 本地時間 |
| $host | 按照以下順序獲取主機資訊:請求行中的主機名,或“Host”請求頭欄位中的主機名,或與請求匹配的服務器名, |
| $hostname | 主機名 |
| $http_name | 表示任意請求頭;name 為請求頭名稱,其中破折號被下劃線替換并轉換為小寫;如:$http_user_agent,$http_x_forwarded_for |
| $proxy_add_x_forwarded_for | 將 $remote_addr 的值附加到“X?Forwarded?For”客戶端請求頭中,由逗號分隔,如果客戶端請求頭中不存在“X?Forwarded?For”,則 $proxy_add_x_forwarded_for 等于 $remote_addr , |
| $proxy_host | 代理服務器的地址和埠 |
| $proxy_port | 代理服務器的埠 |
| $query_string | 同 $args |
| $remote_addr | 客戶端地址 |
| $remote_port | 客戶端埠 |
| $remote_user | Basic 身份驗證中提供的用戶名 |
| $request | 完整請求行 |
| $request_body | 請求體 |
| $request_body_file | 保存請求體的臨時檔案 |
| $request_length | 請求長度(包括請求行、頭部和請求體) |
| $request_method | 請求方法 |
| $request_time | 請求處理時間,單位為:ms |
| $request_uri | 完整請求行 |
| $scheme | 請求協議,http 或 https |
| $server_addr | 接受請求的服務器地址 |
| $server_name | 接受請求的服務器名稱 |
| $server_port | 接受請求的服務器埠 |
| $server_protocol | 請求協議,通常為 HTTP/1.0、HTTP/1.1 或 HTTP/2.0 |
| $ssl_cipher | 建立 SSL 連接所使用的加密套件名稱 |
| $ssl_ciphers | 客戶端支持的加密套件串列 |
| $ssl_client_escaped_cert | 客戶端 PEM 格式的證書 |
| $ssl_protocol | 建立 SSL 連接的協議 |
| $status | 回應狀態碼 |
| $time_iso8601 | ISO 8601 標準格式的本地時間 |
| $time_local | Common Log 格式的本地時間 |
| $upstream_addr | upstream 服務器的 ip 和埠 |
| $upstream_bytes_received | 從 upstream 服務器接收的位元組數 |
| $upstream_bytes_sent | 發送給 upstream 服務器的位元組數 |
| $upstream_http_name | 表示 upstream 服務器任意回應頭,name 為回應頭名稱,其中破折號被下劃線替換并轉換為小寫 |
| $upstream_response_length | upstream 服務器的回應長度,單位為:位元組 |
| $upstream_response_time | upstream 服務器的回應時間,單位為:秒 |
| $upstream_status | upstream 服務器的回應狀態碼 |
| $uri | 請求 uri |
參考:https://nginx.org/en/docs/varindex.html,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/552425.html
標籤:其他
上一篇:內網本地資訊收集
下一篇:返回列表
