nginx內嵌變量

FORWARD:http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html#variables

ngx_http_core_module模塊支持內嵌變量,變量名與Apache服務器對應。 首先,這些變量可以表示客戶端的請求頭字段,諸如$http_user_agent、$http_cookie等等。 nginx也支持其他變量:

$arg_name
請求行中的name參數。
$args
請求行中參數字符串。
$binary_remote_addr
客戶端IP地址的二進制形式,值的長度總是4字節。
$body_bytes_sent
nginx返回給客戶端的字節數,不含響應頭。
$bytes_sent
nginx返回給客戶端的字節數(1.3.8, 1.2.5)。
$connection
連接的序列號(1.3.8, 1.2.5)。
$content_length
“Content-Length”請求頭的值。
$content_type
“Content-Type”請求頭的值。
$cookie_name
名爲name的cookie。
$document_root
當前請求的root指令或alias指令的配置值。
$document_uri
與$uri相同。
$host
“Host”請求頭的值,如果沒有該請求頭,則爲與請求對應的虛擬主機的首要主機名。
$hostname
機器名稱。
$http_name
任意請求頭的值;變量名的後半部爲轉化爲小寫並且用下劃線替代橫線後的請求頭名稱。
$https
如果連接是SSL模塊,返回“on”,否則返回空字符串。
$is_args
如果請求行帶有參數,返回“?”,否則返回空字符串。
$limit_rate
允許設置此值來限制連接的傳輸速率。
$msec
當前時間,單位是秒,精度是毫秒。(1.3.9, 1.2.6)
$nginx_version
nginx版本號。
$pid
worker進程的PID。
$query_string
與$args相同。
$realpath_root
按root指令或alias指令算出的當前請求的絕對路徑。其中的符號鏈接都會解析成真是文件路徑。
$remote_addr
客戶端IP地址。
$remote_port
客戶端端口。
$remote_user
爲基本用戶認證提供的用戶名。
$request
完整的原始請求行。
$request_body
請求正文。
在由proxy_pass指令和 fastcgi_pass指令處理的路徑中, 這個變量值可用。

$request_body_file
請求正文的臨時文件名。
處理完成時,臨時文件將被刪除。 如果希望總是將請求正文寫入文件,需要開啓client_body_in_file_only。 如果在被代理的請求或FastCGI請求中傳遞臨時文件名,就應該禁止傳遞請求正文本身。 使用proxy_pass_request_body off指令 和fastcgi_pass_request_body off指令 分別禁止在代理和FastCGI中傳遞請求正文。

$request_completion
請求完成時返回“OK”,否則返回空字符串。
$request_filename
基於root指令或alias指令,以及請求URI,得到的當前請求的文件路徑。
$request_method
HTTP方法,通常爲“GET”或者“POST”。
$request_time
請求處理的時間,單位爲秒,精度是毫秒(1.3.9, 1.2.6);請求處理時間從由客戶端接收到第一個字節開始計算。
$request_uri
完整的原始請求行(帶參數)。
$scheme
請求協議類型,爲“http”或“https”。
$sent_http_name
任意的響應頭字段的值。 變量名的後半部爲轉化爲小寫並且用下劃線替代橫線後的響應頭名稱。
$server_addr
接受請求的服務器地址。
爲計算這個值,通常需要進行一次系統調用。爲了避免系統調用,必須指定listen指令 的地址,並且使用bind參數。

$server_name
接受請求的虛擬主機的首要主機名。
$server_port
接受請求的虛擬主機的端口。
$server_protocol
請求協議,通常爲“HTTP/1.0”或“HTTP/1.1”。
$status
響應狀態碼。
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space
客戶端TCP連接的信息,在支持套接字選項TCP_INFO的系統中可用。
$uri
當前請求規範化以後的URI。

nginx.conf 這裏不是用於做ELK收集日誌

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
     worker_connections 768;
}

http {

     sendfile on;
     tcp_nopush on;
     tcp_nodelay on;
     keepalive_timeout 65;
     types_hash_max_size 2048;

     include /etc/nginx/mime.types;
     default_type application/octet-stream;

     log_format logstash_json '{ "timestamp": "$time_local", '
                         '"host": "$host", '
                         '"remote_addr": "$remote_addr", '
                         '"remote_user": "$remote_user", '
                         '"body_bytes_sent": "$body_bytes_sent", '
                         '"request_time": "$request_time", '
                         '"status": "$status", '
                         '"args": "$args", '
                         '"request": "$request", '
                         '"request_method": "$request_method", '
                         '"http_referrer": "$http_referer", '
                         '"document_uri": "$document_uri", '
                         '"body_bytes_sent":"$body_bytes_sent", '                         
                         '"bytes_sent":"$bytes_sent", '
                         '"http_x_forwarded_for": "$http_x_forwarded_for", '
                         '"http_user_agent": "$http_user_agent" }';
        access_log /var/log/nginx/access.log logstash_json;
     error_log /var/log/nginx/error.log;

     gzip on;
     gzip_disable "msie6";

     include /etc/nginx/conf.d/*.conf;
     include /etc/nginx/sites-enabled/*;
}
# tail -1 access.log 
{ "timestamp": "28/Dec/2017:15:05:17 +0800", "host": "www.weiops.com", "remote_addr": "124.204.59.157", "remote_user": "-", "body_bytes_sent": "209", "request_time": "0.000", "status": "404", "args": "name=zuowenhong", "request": "GET /index?name=zuowenhong HTTP/1.1", "request_method": "GET", "http_referrer": "-", "document_uri": "/index", "body_bytes_sent":"209", "bytes_sent":"404", "http_x_forwarded_for": "-", "http_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章