The HTTP Core module introduces a large set of variables that you can use within the value of directives. Be careful though, as only a handful of directives accept variables in the definition of their value. If you insert a variable in the value of a directive that does not accept variables, no error is reported; instead the variable name appears as raw text.

There are three different kinds of variables that you will come across. The first set represents the values transmitted in the headers of the client request. The second set corresponds to the headers of the response sent to the client. Finally, the third set comprises variables that are completely generated by Nginx.

Request Headers

Nginx lets you access the client request headers under the form of variables that you will be able to employ later on in the configuration:

Variable Description
 $http_host  Value of the Host HTTP header, a string indicating the hostname that the client is trying to reach.
 $http_user_agent   Value of the User-Agent HTTP header, a string indicating the web browser of the client.
 $http_referer   Value of the Referer HTTP header, a string indicating the URL of the previous page from which the client comes. 
 $http_via   Value of the Via HTTP header, which informs us about possible proxies used by the client.
 $http_x_forwarded_for   Value of the X-Forwarded-For HTTP header, which shows the actual IP address of the client if the client is behind a proxy. 
 $http_cookie  Value of the Cookie HTTP header, which contains the cookie data sent by the client.
 $http_...   Additional headers sent by the client can be retrieved using $http_ followed by the header name in lowercase and with dashes (-) replaced by underscores (_).

Response headers

In a similar fashion, you are allowed to access the HTTP headers of the response that was sent to the client. These variables are not available at all times — they will only carry a value after the response is sent, for instance, at the time of writing messages in the logs.

Variable Description
 $sent_http_content_type   Value of the Content-Type HTTP header, indicating the MIME type of the resource being transmitted.
 $sent_http_content_length   Value of the Content-Length HTTP header informing the client of the response body length.
 $sent_http_location   Value of the Location HTTP header, which indicates that the location of the desired resource is different than the one specified in the original request.
 $sent_http_last_modified  Value of the Last-Modified HTTP header corresponding to the modification date of the requested resource.
 $sent_http_connection   Value of the Connection HTTP header, defining whether the connection will be kept alive or closed.
 $sent_http_keep_alive  Value of the Keep-Alive HTTP header that defines the amount of time a connection will be kept alive.
 $sent_http_transfer_encoding   Value of the Transfer-Encoding HTTP header, giving information about the response body encoding method (such as compress, gzip).
 $sent_http_cache_control  Value of the Cache-Control HTTP header, telling us whether the client browser should cache the resource or not.
 $sent_http_...  Additional headers sent to the client can be retrieved using $sent_http_ followed by the header name, in lowercase and with dashes (-) replaced by underscores (_).

Nginx Generated

Apart from the HTTP headers, Nginx provides a large amount of variables concerning the request, the way it was and will be handled, as well as settings in use with the current configuration.

Variable Description
 $arg_XXX   Allows you to access the query string (GET parameters), where XXX is the name of the parameter you want to utilize. 
 $args  All of the arguments of the query string combined together.
 $binary_remote_addr   IP address of the client as binary data (4 bytes).
 $body_bytes_sent  Amount of bytes sent in the body of the response.
 $connection_requests   Amount of requests already served by the current connection.
 $content_length  Equates to the Content-Length HTTP header.
 $content_type  Equates to the Content-Type HTTP header.
 $cookie_XXX  Allows you to access cookie data where XXX is the name of the parameter you want to utilize.
 $document_root   Returns the value of the root directive for the current request.
 $document_uri  Returns the current URI of the request. It may differ from the original request URI if internal redirects were performed. It is identical to the $uri variable.
 $host  This variable equates to the Host HTTP header of the request. Nginx itself gives this variable a value for cases where the Host header is not provided in the original request.
 $hostname  Returns the system hostname of the server computer
 $https  Set to on for HTTPS connections, empty otherwise.
 $is_args  If the $args variable is defined, $is_args equates to ?. If $args is empty, $is_args is empty as well. You may use this variable for constructing an URI that optionally comes with a query string, such as index.php$is_args$args. If there is any query string argument in the request, $is_args is set to ?, making this a valid URI.
 $limit_rate 

Returns the per-connection transfer rate limit, as defined by the limit_rate directive. You are allowed to edit this variable by using set (directive from the Rewrite Module):

set $limit_rate 128k;

 $nginx_version  Returns the version of Nginx you are running.
 $pid  Returns the Nginx process identifier.
 $query_string  Identical to $args.
 $remote_addr   Returns the IP address of the client.
 $remote_port  Returns the port of the client socket.
 $remote_user  Returns the client username if they used authentication.
 $realpath_root  Returns the document root in the client request, with symbolic links resolved into the actual path.
 $request_body   Returns the body of the client request, or - if the body is empty.
 $request_body_file  If the request body was saved (see the client_body_in_file_only directive) this variable indicates the path of the temporary file.
 $request_completion   Returns OK if the request is completed, an empty string otherwise.
 $request_filename  Returns the full filename served in the current request.
 $request_method  Indicates the HTTP method used in the request, such as GET or POST.
 $request_uri  Corresponds to the original URI of the request, remains unmodified all along the process (unlike $document_uri/$uri).
 $scheme   Returns either http or https, depending on the request.
 $server_addr   Returns the IP address of the server. Be aware as each use of the variable requires a system call, which could potentially affect overall performance in the case of high-traffic setups.
 $server_name  Indicates the value of the server_name directive that was used while processing the request.
 $server_port  Indicates the port of the server socket that received the request data.
 $server_protocol  Returns the protocol and version, usually HTTP/1.0 or HTTP/1.1.

$tcpinfo_rtt,
 $tcpinfo_rttvar,
 $tcpinfo_snd_cwnd,
 $tcpinfo_rcv_space

If your operating system supports the TCP_INFO socket option, these variables will be populated with information on the
current client TCP connection.

$time_iso8601,
 $time_local

 Provides the current time respectively in ISO 8601 and local formats for use with the access_log directive.
 $uri  Identical to $document_uri.

Nginx - HTTP Configuration, Module Variables的更多相关文章

  1. Nginx - HTTP Configuration, Module Directives

    Socket and Host Configuration This set of directives will allow you to configure your virtual hosts. ...

  2. Nginx之旅系列 - Nginx的configuration

    题记:Nginx之旅系列是用来记录Nginx从使用到源码学习的点点滴滴,分享学习Nginx的快乐 Nginx 首页: http://nginx.org/ Nginx的configuration 今天对 ...

  3. - configuration.module has an unknown property 'loader' 问题解决

    错误提示: Invalid configuration object. Webpack has been initialised using a configuration object that d ...

  4. Nginx - HTTP Configuration, the Location Block

    Nginx offers you the possibility to fine-tune your configuration down to three levels — at the proto ...

  5. nginx install lua module

    #install luajit #http://luajit.org/download.html .tar.gz cd LuaJIT- make install PREFIX=/home/allen. ...

  6. Test,Nginx Hello World Module

    ngx_addon_name=ngx_http_mytest_module HTTP_MODULES="$HTTP_MODULES ngx_http_mytest_module" ...

  7. Nginx - Configuration File Syntax

    Configuration Directives The Nginx configuration file can be described as a list of directives organ ...

  8. Nginx - Rewrite Module

    Initially, the purpose of this module (as the name suggests) is to perform URL rewriting. This mecha ...

  9. nginx tcp负载均衡 (Module ngx_stream_upstream_module)

    Example ConfigurationDirectives     upstream     server     zone     state     hash     least_conn   ...

随机推荐

  1. Light oj 1234 - Harmonic Number

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1234 给你一个数n,让你求 这个要是直接算的话肯定TLE,要是用1e8的数组预处理存储 ...

  2. JavaScript- 获取经度纬度

    昨天获得一个小需求,需要取地理位置. 通过以下的JS能获得经度和纬 if(navigator.geolocation) { navigator.geolocation.getCurrentPositi ...

  3. 如何让自己的电脑发布ASP http://jingyan.baidu.com/article/19192ad853224ce53f570748.html

    怎样在WIN7系统下安装IIS | 浏览:122821 | 更新:2012-03-03 14:07 | 标签:windows7 1 2 3 4 5 6 7 分步阅读 在此根据多年的网站开发经验,把如何 ...

  4. BZOJ 1043 HAOI2008 下落的圆盘 计算几何

    题目大意:n个圆盘依次下落.求终于能看到的轮廓线面积 円盘反对! 让我们一起团结起来! 赶走円盘! 咳咳.非常神的一道题 今天去看了题解和白书才搞出来-- 首先我们倒着做 对于每一个圆盘处理出在它之后 ...

  5. Codeforces Gym 100500F Problem F. Door Lock 二分

    Problem F. Door LockTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/at ...

  6. Cache选型的一些思考

    Cache对于减轻DB负载有非常关键的数据.以下对经常使用的memcached和redis做个总结,便于技术选型. 1 memcached  (1) 支持的操作有限,支持经常使用的set,get,de ...

  7. iOS开发——UI篇&九宫格算法

    九宫格算法 关于iOS开发中九宫格的实现虽然使用不多,而且后面会有更好的方实现,但是作为一个程序员必需要知道的就是九宫格算法的实现. 一:实现思路: (1)明确每一块用得是什么view (2)明确每个 ...

  8. UVA 1401 - Remember the Word(Trie+DP)

    UVA 1401 - Remember the Word [题目链接] 题意:给定一些单词.和一个长串.问这个长串拆分成已有单词,能拆分成几种方式 思路:Trie,先把单词建成Trie.然后进行dp. ...

  9. debian下软件包管理方式总结

    linux最流行的包管理方式除了rpm之外就是debian的deb格式了.目前采用deb管理方式的主流操作系统主要有debian和ubuntu系列.和rpm包管理方式不同的是,虽然debian也有包含 ...

  10. Innode引擎监控的开启的方法

    查看当前InnoDB引擎信息 mysql> show innodb status\G 开启InnoDB监控,有四种: 1. innodb_monitor mysql> create tab ...