Nginx embedded variables are very commonly used. Record them for future reference.
Nginx embedded variables are defined byngx_http_core_module
Module support, variable name corresponding to Apache server, these variables can represent client request header fields, such as$http_user_agent
、$http_cookie
wait. Nginx also supports other variables:
Parameter name | explain |
---|---|
$arg_name | The parameter name in the request, i.e. Arg after ‘?’_ name=arg_ Arg in the form of value_ Name, such as/ index.php?www=www .13 sai.com , you can use $arg_ WWW is www.13sai.com |
$args | Parameter values in the request |
$binary_remote_addr | The binary form of the client address with a fixed length of 4 bytes |
$body_bytes_sent | The number of bytes transferred to the client, the response header is not counted; this variable and Apache Mod_ log_ The% B parameter in the config module remains compatible |
$bytes_sent | The number of bytes transferred to the client |
$connection | The serial number of the TCP connection |
$connection_requests | The current number of requests for TCP connections |
$content_length | “Content length” request header field |
$content_type | “Content type” request header field |
$cookie_name | Cookie name |
$document_root | The document root or alias of the current request |
$document_uri | Same as $URI |
$host | The priority is as follows: the host name of HTTP request line > the “host” request header field > the server name that matches the request |
$hostname | host name |
$http_name | Match any request header field; the last half of the variable name “name” can be replaced with any request header field. If you need to obtain the HTTP request header: “accept language” in the configuration file, replace “-” with an underline, and replace upper case letters with lowercase letters, as shown in $http_ accept_ Language. |
$https | If SSL security mode is enabled, the value is “on”, otherwise it is an empty string. |
$is_args | If there is a parameter in the request, the value is’? ‘, otherwise it is an empty string. |
$limit_rate | Used to set the response speed limit. See limit for details_ rate。 |
$msec | Current UNIX timestamp (1.3.9, 1.2.6) |
$nginx_version | Nginx version |
$pid | PID of work process |
$pipe | Value “P” if request is from pipeline communication, otherwise “.” (1.3.12, 1.2.7) |
$proxy_protocol_addr | Gets the client address of the proxy access server. If it is direct access, the value is an empty string. (1.5.12) |
$query_string | Same as $args, however $query_ String is read-only and does not change |
$realpath_root | The real path of the currently requested document root or alias will convert all symbolic connections to real paths. |
$remote_addr | Client address |
$remote_port | Client port |
$remote_user | The user name used for the HTTP basic authentication service |
$request | The request address representing the client |
$request_body | The client’s request body. This variable can be used in location to send the request body through proxy_ pass, fastcgi_ pass, uwsgi_ Pass, and SCGI_ Pass is passed to the next level proxy server. |
$request_body_file | The temporary file name of the body of the request. When processing is complete, the temporary file will be deleted. If you want to always write the request body to a file, you need to turn on client_ body_ In_ file_ only。 If the temporary file name is passed in the proxy request or fastcgi request, the transfer of the request body itself should be prohibited. Using proxy_ pass_ request_ Body off instruction and fastcgi_ pass_ request_ The body off instruction forbids passing the request body in the proxy and fastcgi respectively. |
$request_completion | The value is “OK” if the request is successful, and null if the request is not completed or if the request is not the last part of a scope request. |
$request_filename | The file path of the current connection request, generated by the root or alias instruction and URI request. |
$request_length | The length of the request (including the address of the request, HTTP request header and request body) |
$request_method | HTTP request method, usually “get” or “post” |
$request_time | The time used to process client requests; counts from the first byte of the client. |
$request_uri | This variable is equal to the original URI containing some client request parameters. It cannot be modified. Please check the $URI to change or rewrite the URI, which does not contain the host name, for example: ‘/ Sai/ test.php?arg=www ”。 |
$scheme | The web protocol to be used, “HTTP” or “HTTPS” |
$sent_http_name | You can set any HTTP response header field; the last half of the variable name “name” can be replaced with any response header field. If you need to set the response header content length, replace “-” with an underline, and replace upper case letters with lowercase letters, as shown in $send_ http_ content_ Length 4096 is enough. |
$server_addr | It should be noted that the IP address should be set in the configuration file in advance in order to avoid accessing the Linux kernel. |
$server_name | server name |
$server_port | Server port |
$server_protocol | The HTTP version of the server, usually “http / 1.0” or “http / 1.1” |
$status | HTTP response code |
$time_iso8601 | ISO 8610 format of server time |
$time_local | The server time (log format format format) is the time when nginx completes processing and printing the log, not the time when the request is issued |
$uri | The current URI in the request (without request parameters, at $args) can be different from the $request passed by the browser_ URI, which can be modified by internal redirection or by using the index command. The $URI does not contain a host name, such as’ / foo ‘/ bar.html ”。 |
Apache server variables can be viewed[Apache] server
reference resources:
Nginx related articles:
- Nginx load balancing
- Nginx adds Lua module
- Nginx configuration common parameters, read this article is enough
- Nginx proxy cache
The technical article is also published in its official account, a history loving programmer. Welcome to scan code attention. Thank you!
This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint