Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the built-in variables of nginx

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today Xiaobian to share with you what nginx built-in variables have related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you have some gains after reading this article, let's learn about it together.

nginx built-in variables

Built-in variables are stored in the ngx_http_core_module module, and the naming of variables is consistent with apache server variables. In summary, these variables represent the contents of the client request header, such as $http_user_agent, $http_cookie, and so on. Here are all the built-in variables supported by nginx:

$arg_name

The name of the parameter in the request, i.e."? arg_name of the form arg_value followed by arg_name=

$args

Parameter values in the request

$binary_remote_addr

Binary form of client address, fixed length 4 bytes

$body_bytes_sent

Number of bytes transferred to client, not counting response headers; this variable is compatible with the ' %b' parameter in apache mod_log_config module

$bytes_sent

Number of bytes transferred to client (1.3.8, 1.2.5)

$connection

sequence number of tcp connection (1.3.8, 1.2.5)

$connection_requests

Number of TCP connections currently requested (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

Document root or alias for the current request

$document_uri

Same as $uri

$host

The priority is as follows: http host name of request line>"host" request header field> server name matching request

$hostname

hostname

$http_name

Match 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 http request header: "accept-language" in the configuration file, replace "-" with underscore, and replace uppercase letters with lowercase, such as: $http_accept_language.

$https

The value is "on" if ssl security mode is enabled, otherwise an empty string.

$is_args

If there are parameters in the request, the value is "? ", otherwise empty string.

$limit_rate

Used to set the speed limit of the response, see limit_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 pipe traffic, otherwise ". " (1.3.12, 1.2.7)

$proxy_protocol_addr

Gets the client address of the proxy access server. If it is a direct access, this value is an empty string. (1.5.12)

$query_string

Same as $args

$realpath_root

The real path to the root or alias of the currently requested document converts all symbolic links to real paths.

$remote_addr

client address

$remote_port

client port

$remote_user

User name for http basic authentication service

$request

Represents the request address of the client

$request_body

The client's request body

This variable can be used in location to pass the request body to the next level proxy server via proxy_pass, fastcgi_pass, uwsgi_pass, and scgi_pass.

$request_body_file

Save the client request body in a temporary file. After processing the file, the file needs to be deleted. If you want one of these to turn on, you need to set client_body_in_file_only. If the secondary file is passed to the backend proxy server, you need to disable the request body, i.e. 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, and null 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 directive and uri request.

$request_length

Length of request (including request address, http request header and request body) (1.3.12, 1.2.7)

$request_method

http request method, usually "get" or "post"

$request_time

Time used to process client requests (1.3.9, 1.2.6); starts counting from reading 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 see $uri change or rewrite uri, does not contain the host name, for example: "/cnphp/test.php? arg=freemouse"。

$scheme

The web protocol used by 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 underscore and replace upper case letters with lowercase, such as $sent_http_content_length 4096.

$server_addr

Server-side address, it is necessary to note that in order to avoid accessing the linux system kernel, the ip address should be set in advance in the configuration file.

$server_name

Server name, www.cnphp.info

$server_port

server port

$server_protocol

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

Details of client tcp connections

$time_iso8601

iso 8610 format for server time (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, at $args) can be different from the value of $request_uri passed by the browser, which can be modified by internal redirection or by using the index directive,$uri does not contain the hostname, such as "/foo/bar.html".

nginx built-in global variables and their meanings

Name Version description (variable list from file ngx_http_variables)

$args 1.0.8 Parameters in the request;

$binary_remote_addr 1.0.8 Binary representation of a remote address

$body_bytes_sent 1.0.8 Number of body bytes sent

$content_length 1.0.8 "content-length" in http request message;

$content_type 1.0.8 "content-type" in the request message;

$document_root 1.0.8 sets the value for the root path of the current request;

$document_uri 1.0.8 is the same as $uri; for example/test1/test2/test.php

$host1.0.8 "host" in the request information, if there is no host line in the request, it is equal to the server name set;

$hostname 1.0.8

$http_cookie 1.0.8 cookie information

$http_post 1.0.8

$http_referrer 1.0.8 Reference address

$http_user_agent 1.0.8 Client proxy information

$http_via 1.0.8 IP address of the last visited server.

$http_x_forwarded_for 1.0.8 corresponds to the network access path.

$is_args 1.0.8

$limit_rate 1.0.8 Limit on connection rate;

$nginx_version 1.0.8

$pid 1.0.8

$query_string 1.0.8 is the same as $args;

$realpath_root 1.0.8

$remote_addr 1.0.8 Client address;

$remote_port 1.0.8 client port number;

$remote_user 1.0.8 Client user name for authentication;

$request 1.0.8 User request

$request_body 1.0.8

$request_body_file 1.0.8 Local file name sent to backend

$request_completion 1.0.8

$request_filename 1.0.8 Path name of the file currently requested, e.g.$request_filename: d:\nginx/html/test1/test2/test.php

$request_method 1.0.8 The method of the request, such as "get","post", etc.;

$request_uri 1.0.8 URI requested, with parameters; e.g. http://localhost:88/test1/test2/test.php

The protocol used by $scheme 1.0.8, 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 the server address is not specified with listen, using this variable will initiate a system call to get the address (causing waste of resources);

$server_name 1.0.8 The name of the server on which the request arrived;

$server_port 1.0.8 The server port number on which the request arrived;

$server_protocol 1.0.8 Protocol version requested,"http/1.0" or "http/1.1";

$uri 1.0.8 The uri requested may be different from the original value, e.g. after redirection.

The above is "What are the built-in variables of nginx" All the contents of this article, thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report