Home > Article > Operation and Maintenance > What are the built-in variables of nginx?
nginx built-in variables
Built-in variables are stored in the ngx_http_core_module module. The naming method of variables is consistent with the apache server variables. In summary, these variables represent the contents of client request headers, such as $http_user_agent, $http_cookie, etc. The following are all built-in variables supported by nginx:
$arg_name
The parameter name in the request, that is, the arg_name=arg_value form after "?"
$args
Parameter value in the request
$binary_remote_addr
The binary form of the client address, fixed length is 4 bytes
$body_bytes_sent
The number of bytes transmitted to the client, response Headers are not counted; this variable is compatible with the "%b" parameter in apache's mod_log_config module
$bytes_sent
The number of bytes transmitted to the client (1.3.8, 1.2.5)
$connection
The serial number of the tcp connection (1.3.8, 1.2.5)
$connection_requests
The current number of requests for the tcp connection (1.3.8, 1.2.5)
$content_length
"content-length" request header field
$content_type
"content-type" request header field
$cookie_name
cookie Name
$document_root
The document root directory or alias of the current request
$document_uri
Same as $uri
$host
The priority is as follows: http The host name of the request line>"host" request header field>matches the requested server name
$hostname
Host name
$http_name
matches any request header field; The second half of the variable name "name" can be replaced with any request header field. For example, if you need to obtain the http request header: "accept-language" in the configuration file, replace "-" with an underscore and uppercase letters with lowercase. The format is: $http_accept_language.
$https
If ssl security mode is enabled, the value is "on", otherwise it is an empty string.
$is_args
If there are parameters in the request, the value is "?", otherwise it is an empty string.
$limit_rate
is used to set the speed limit of the response, see limit_rate for details.
$msec
Current unix timestamp (1.3.9, 1.2.6)
$nginx_version
nginx version
$pid
Working The pid of the process
$pipe
If the request comes from pipe communication, the value is "p", otherwise it is "." (1.3.12, 1.2.7)
$proxy_protocol_addr
Get 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
$realpath_root
The real path of the currently requested document root or alias, will convert all symbolic links to real path.
$remote_addr
Client address
$remote_port
Client port
$remote_user
Username used for http basic authentication service
$request
Represents the client's request address
$request_body
The client's request body
This variable can be used in location to pass the request body through proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass passed to the next level proxy server.
$request_body_file
Save the client request body in a temporary file. After file processing is completed, this file needs to be deleted. If you need to enable this feature, you need to set client_body_in_file_only. If you pass the secondary file to the back-end proxy server, you need to disable the request body, that is, set proxy_pass_request_body off, fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off.
$request_completion
The value is "ok" if the request is successful, or empty if the request is incomplete or the request is not the last part of a range request.
$request_filename
The file path of the current connection request, generated by the root or alias command and the uri request.
$request_length
The length of the request (including the requested address, http request header and request body) (1.3.12, 1.2.7)
$request_method
http request method , usually "get" or "post"
$request_time
The time used to process client requests (1.3.9, 1.2.6); starting from the first byte read from the client .
$request_uri
This variable is equal to the original uri containing some client request parameters, it cannot be modified, please see $uri to change or rewrite the uri, does not contain the host name, for example: "/cnphp/test .php?arg=freemouse”.
$scheme
The web protocol used in the request, "http" or "https"
$sent_http_name
You can set any http response header field; the second 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 underscore and uppercase letters with lowercase letters, such as: $sent_http_content_length 4096.
$server_addr
Server-side address, it should be noted that in order to avoid accessing the Linux system kernel, the IP address should be set in the configuration file in advance.
$server_name
Server name, www.cnphp.info
$server_port
Server port
$server_protocol
The http version of the server, usually "http/1.0" or "http/1.1"
$status
http response code (1.3.2, 1.2.2)
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $ tcpinfo_rcv_space
Detailed information of client tcp connection
$time_iso8601
Server time in iso 8610 format (1.3.12, 1.2.7)
$time_local
Server time (log format) (1.3.12, 1.2.7)
$uri
The current uri in the request (without request parameters, the parameters are located in $args), can be different from the value of $request_uri passed by the browser, it can be through internal redirection, or using index The command is modified so that $uri does not contain the host name, such as "/foo/bar.html".
nginx built-in global variables and their meaning
Name Version Description (the variable list comes from the file ngx_http_variables)
$args 1.0.8 Parameters in the request;
$binary_remote_addr 1.0.8 Binary representation of the remote address
$body_bytes_sent 1.0.8 Sent The number of bytes in the message body
$content_length 1.0.8 The "content-length";
$content_type in the http request information 1.0.8 The "content-type" in the request information;
$document_root 1.0. 8 Set the value for the root path of the current request;
$document_uri 1.0.8 The same as $uri; such as /test1/test2/test.php
$host 1.0.8 "host" in the request information, if the request If there is no host line, it is equal to the set server name;
$hostname 1.0.8
$http_cookie 1.0.8 Cookie information
$http_post 1.0.8 Reference address
$http_user_agent 1.0.8 Client agent information
$http_via 1.0.8 The last IP address to access the server.
$http_x_forwarded_for 1.0.8 Equivalent to the network access path.
$is_args 1.0.8
$limit_rate 1.0.8 Limitation on connection rate;
$nginx_version 1.0.8
$pid 1.0.8
$query_string 1.0.8 Same as $args ;
$realpath_root out ’ down ’ out down out out out out out off out out out way off out way’psy Inc’psypsypsypsypsycompatibility out way’psy’ way way way way way way way way way out way way way way out out way way way out out way way out way way way way way way rightpspspspspspsps outps out out out out out out out out out out out out out out’s together’s ’ ’ down off off down - - - and to the 1.0.8 Client username, used for authentication;
$request 1.0.8 User request
$request_body 1.0.8
$request_body_file 1.0.8 The name of the local file sent to the backend
$request_completion 1.0.8
$request_filename 1.0.8 Current Requested file path name, such as $request_filename: d:\nginx/html/test1/test2/test.php
$request_method 1.0.8 Requested method, such as "get", "post", etc.;
$ request_uri 1.0.8 The requested uri, with parameters; such as http://localhost:88/test1/test2/test.php
$scheme 1.0.8 The protocol used, such as http or https, such as rewrite^(. )$$scheme://example.com$1redirect;
$sent_http_cache_control 1.0.8
$sent_http_connection 1.0.8
$sent_http_content_length 1.0.8
$sent_http_content_type 1.0.8
$sent_http_keep_alive 1.0.8
$sent_http_last_modified 1.0.8
$sent_http_location 1.0.8
$sent_http_transfer_encoding 1.0.8
$server_addr 1.0.8 Server address, if you do not use listen to specify the server address, use this The variable will initiate a system call to get the address (causing waste of resources);
$ Server_name 1.0.8 Request server name;
$ Server_Port 1.0.8 The server -side number of the request; .8 The requested protocol version, "http/1.0" or "http/1.1";
$uri 1.0.8 The requested uri may be different from the original value, such as after redirection.
The above is the detailed content of What are the built-in variables of nginx?. For more information, please follow other related articles on the PHP Chinese website!