search
HomeOperation and MaintenanceNginxWhat 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!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
The Advantages of NGINX: Speed, Efficiency, and ControlThe Advantages of NGINX: Speed, Efficiency, and ControlMay 12, 2025 am 12:13 AM

The reason why NGINX is popular is its advantages in speed, efficiency and control. 1) Speed: Adopt asynchronous and non-blocking processing, supports high concurrent connections, and has strong static file service capabilities. 2) Efficiency: Low memory usage and powerful load balancing function. 3) Control: Through flexible configuration file management behavior, modular design facilitates expansion.

NGINX vs. Apache: Community, Support, and ResourcesNGINX vs. Apache: Community, Support, and ResourcesMay 11, 2025 am 12:19 AM

The differences between NGINX and Apache in terms of community, support and resources are as follows: 1. Although the NGINX community is small, it is active and professional, and official support provides advanced features and professional services through NGINXPlus. 2.Apache has a huge and active community, and official support is mainly provided through rich documentation and community resources.

NGINX Unit: An Introduction to the Application ServerNGINX Unit: An Introduction to the Application ServerMay 10, 2025 am 12:17 AM

NGINXUnit is an open source application server that supports a variety of programming languages ​​and frameworks, such as Python, PHP, Java, Go, etc. 1. It supports dynamic configuration and can adjust application configuration without restarting the server. 2.NGINXUnit supports multi-language applications, simplifying the management of multi-language environments. 3. With configuration files, you can easily deploy and manage applications, such as running Python and PHP applications. 4. It also supports advanced configurations such as routing and load balancing to help manage and scale applications.

Using NGINX: Optimizing Website Performance and ReliabilityUsing NGINX: Optimizing Website Performance and ReliabilityMay 09, 2025 am 12:19 AM

NGINX can improve website performance and reliability by: 1. Process static content as a web server; 2. forward requests as a reverse proxy server; 3. allocate requests as a load balancer; 4. Reduce backend pressure as a cache server. NGINX can significantly improve website performance through configuration optimizations such as enabling Gzip compression and adjusting connection pooling.

NGINX's Purpose: Serving Web Content and MoreNGINX's Purpose: Serving Web Content and MoreMay 08, 2025 am 12:07 AM

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur

NGINX Unit: Streamlining Application DeploymentNGINX Unit: Streamlining Application DeploymentMay 07, 2025 am 12:08 AM

NGINXUnit simplifies application deployment with dynamic configuration and multilingual support. 1) Dynamic configuration can be modified without restarting the server. 2) Supports multiple programming languages, such as Python, PHP, and Java. 3) Adopt asynchronous non-blocking I/O model to improve high concurrency processing performance.

NGINX's Impact: Web Servers and BeyondNGINX's Impact: Web Servers and BeyondMay 06, 2025 am 12:05 AM

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Nginx Troubleshooting: Diagnosing and Resolving Common ErrorsNginx Troubleshooting: Diagnosing and Resolving Common ErrorsMay 05, 2025 am 12:09 AM

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.

See all articles

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 Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool