nginx Embedded Variablesの一覧


nginxには組み込みの変数が$variableという形式でアクセスできます。

ドキュメントには色々書いておりますが、毎回
「実際にどんな値が入るのかな？」
と思いますので、調べました。

# ドキュメント引用

2016/07/12時点です。

http://nginx.org/en/docs/http/ngx_http_core_module.html#variables

※追記：こんなページもあるようです
　http://nginx.org/en/docs/varindex.html
 　(@cubicdaiya ++ !)

|variable|説明|
| :--- |--- |
|$arg_name| argument name in the request line （補足：{name}部分を変えることで、任意のクエリパラメータの値にアクセス出来ます）|
|$args| arguments in the request line |
|$binary_remote_addr| client address in a binary form, value’s length is always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses |
|$body_bytes_sent| number of bytes sent to a client, not counting the response header; this variable is compatible with the “%B” parameter of the mod_log_config Apache module |
|$bytes_sent| number of bytes sent to a client (1.3.8, 1.2.5) |
|$connection| connection serial number (1.3.8, 1.2.5) |
|$connection_requests| current number of requests made through a connection (1.3.8, 1.2.5) |
|$content_length| “Content-Length” request header field |
|$content_type| “Content-Type” request header field |
|$cookie_name| the name cookie |
|$document_root|root or alias directive’s value for the current request |
|$document_uri| same as $uri|
|$host| in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request |
|$hostname| host name |
|$http_name| arbitrary request header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores　　（補足：{name}部分を変えることで、任意のリクエストヘッダにアクセス出来ます。このとき、アルファベットは小文字にし、「-」は「\_」にして記載します。 例えば X-Hoge にアクセスしたいならば、$http_x_hoge となります。） |
|$https| “on” if connection operates in SSL mode, or an empty string otherwise |
|$is_args| “?” if a request line has arguments, or an empty string otherwise |
|$limit_rate| setting this variable enables response rate limiting; see limit_rate|
|$msec| current time in seconds with the milliseconds resolution (1.3.9, 1.2.6) |
|$nginx_version| nginx version |
|$pid| PID of the worker process |
|$pipe| “p” if request was pipelined, “.” otherwise (1.3.12, 1.2.7) |
|$proxy_protocol_addr| client address from the PROXY protocol header, or an empty string otherwise (1.5.12)  The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive. |
|$proxy_protocol_port| client port from the PROXY protocol header, or an empty string otherwise (1.11.0)  The PROXY protocol must be previously enabled by setting the proxy_protocol parameter in the listen directive. |
|$query_string| same as $args|
|$realpath_root| an absolute pathname corresponding to the root or alias directive’s value for the current request, with all symbolic links resolved to real paths |
|$remote_addr| client address |
|$remote_port| client port |
|$remote_user| user name supplied with the Basic authentication |
|$request| full original request line |
|$request_body| request body  The variable’s value is made available in locations processed by the proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass directives when the request body was read to a memory buffer. |
|$request_body_file| name of a temporary file with the request body  At the end of processing, the file needs to be removed. To always write the request body to a file, client_body_in_file_only needs to be enabled. When the name of a temporary file is passed in a proxied request or in a request to a FastCGI/uwsgi/SCGI server, passing the request body should be disabled by the  proxy_pass_request_body off,  fastcgi_pass_request_body off,  uwsgi_pass_request_body off, or  scgi_pass_request_body off directives, respectively. |
|$request_completion| “OK” if a request has completed, or an empty string otherwise |
|$request_filename| file path for the current request, based on the root or alias directives, and the request URI |
|$request_id| unique request identifier generated from 16 random bytes, in hexadecimal (1.11.0) |
|$request_length| request length (including request line, header, and request body) (1.3.12, 1.2.7) |
|$request_method| request method, usually “GET” or “POST” |
|$request_time| request processing time in seconds with a milliseconds resolution (1.3.9, 1.2.6); time elapsed since the first bytes were read from the client |
|$request_uri| full original request URI (with arguments) |
|$scheme| request scheme, “http” or “https” |
|$sent_http_name| arbitrary response header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores |
|$server_addr| an address of the server which accepted a request  Computing a value of this variable usually requires one system call. To avoid a system call, the listen directives must specify addresses and use the bind parameter. |
|$server_name| name of the server which accepted a request |
|$server_port| port of the server which accepted a request |
|$server_protocol| request protocol, usually “HTTP/1.0”, “HTTP/1.1”, or “HTTP/2.0” |
|$status| response status (1.3.2, 1.2.2) |
|\$tcpinfo_rtt, \$tcpinfo_rttvar, \$tcpinfo_snd_cwnd, \$tcpinfo_rcv_space| information about the client TCP connection; available on systems that support the TCP_INFO socket option |
|$time_iso8601| local time in the ISO 8601 standard format (1.3.12, 1.2.7) |
|$time_local| local time in the Common Log Format (1.3.12, 1.2.7) |
|$uri| current URI in request, normalized The value of $uri may change during request processing, e.g. when doing internal redirects, or when using index files. |



# リクエスト結果


- nginxバージョン
    - nginx 1.11.0
- リクエストURL
    - http://takada.example.com/conf-test/path?name=hogehoge&arg2=fugafuga#hash

レスポンスは
"body\n"（\nは改行）
という中身のファイルです。

|Variable名|実際の値|
|:---|---|
|arg_name|hogehoge|
|args|name=hogehoge&arg2=fugafuga|
|binary_remote_addr|\xC0\xA8\x00\x01|
|body_bytes_sent|5|
|bytes_sent|254|
|connection|579|
|connection_requests|3|
|content_length|-|
|content_type|-|
|cookie_name|-|
|document_root|/var/www/takada|
|document_uri|/conf-test/path|
|host|takada.example.com|
|hostname|dummy-host|
|http_name|-|
|https|  |
|is_args|?|
|limit_rate|0|
|msec|1468303435.418|
|nginx_version|1.11.2|
|pid|18163|
|pipe|.|
|proxy_protocol_addr|  |
|proxy_protocol_port|  |
|query_string|name=hogehoge&arg2=fugafuga|
|realpath_root|/var/www/takada|
|remote_addr|192.168.0.1|
|remote_port|17873|
|remote_user|-|
|request|GET /conf-test/path?name=hogehoge&arg2=fugafuga HTTP/1.1|
|request_body|-|
|request_body_file|-|
|request_completion|OK|
|request_filename|/var/www/takada/conf-test/path|
|request_id|91f47afaceb2183206ab115556629bdc|
|request_length|518|
|request_method|GET|
|request_time|0.000|
|request_uri|/conf-test/path?name=hogehoge&arg2=fugafuga|
|scheme|http|
|sent_http_name|-|
|server_addr|192.168.0.1|
|server_name|takada.example.com|
|server_port|80|
|server_protocol|HTTP/1.1|
|status|200|
|tcpinfo_rtt|10000, 3750, 10, 14600|
|time_iso8601|2016-07-12T15:03:55+09:00|
|time_local|12/Jul/2016:15:03:55 +0900|
|uri|/conf-test/path|