Home Operation and Maintenance Nginx What are the built-in variables of nginx?

What are the built-in variables of nginx?

May 26, 2023 pm 04:16 PM
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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

See all articles