Nginx在使用过程中,有不少的内置全局变量可以用做条件判断和编程控制,本文总结一些已知的指令,以供参考。

$arg_PARAMETER  这个变量包含在查询字符串时GET请求PARAMETER的值。

$args  这个变量等于请求行中的参数。

$binary_remote_addr  二进制码形式的客户端地址。

$body_bytes_sent  传送页面的字节数

$content_length  请求头中的Content-length字段。

$content_type  请求头中的Content-Type字段。

$cookie_COOKIE  cookie COOKIE的值。

$document_root  当前请求在root指令中指定的值。

$document_uri  与$uri相同。

$host  请求中的主机头字段,如果请求中的主机头不可用,则为服务器处理请求的服务器名称。

$is_args  如果$args设置,值为"?",否则为""。

$limit_rate  这个变量可以限制连接速率。

$nginx_version  当前运行的nginx版本号。

$query_string  与$args相同。

$remote_addr  客户端的IP地址。

$remote_port  客户端的端口。

$remote_user  已经经过Auth Basic Module验证的用户名,由ngx_http_auth_basic_module认证。

$request_filename  当前连接请求的文件路径,由root或alias指令与URI请求生成。

$request_body  这个变量(0.7.58+)包含请求的主要信息。在使用proxy_pass或fastcgi_pass指令的location中比较有意义。

$request_body_file  客户端请求主体信息的临时文件名。

$request_completion  未知。

$request_method  这个变量是客户端请求的动作,通常为GET或POST。
包括0.8.20及之前的版本中,这个变量总为main request中的动作,如果当前请求是一个子请求,并不使用这个当前请求的动作。

$request_uri  这个变量等于包含一些客户端请求参数的原始URI,它无法修改,请查看$uri更改或重写URI。

$scheme  所用的协议,比如http或者是https,比如rewrite  ^(.+)$  $scheme://example.com$1  redirect;

$server_addr  服务器地址,在完成一次系统调用后可以确定这个值,如果要绕开系统调用,则必须在listen中指定地址并且使用bind参数。

$server_name  服务器名称。

$server_port  请求到达服务器的端口号。

$server_protocol  请求使用的协议,通常是HTTP/1.0或HTTP/1.1。

$uri  请求中的当前URI(不带请求参数,参数位于$args),可以不同于浏览器传递的$request_uri的值,它可以通过内部重定向,或者使用index指令进行修改。

另外:
HTTP_X_FORWARDED_FOR是透过代理服务器取得客户端的真实IP地址,有些用此方法读取到的仍然是代理服务器的IP。还有一点需要注意的是:如果客户端没有通过代理服务器来访问,那么用 HTTP_X_FORWARDED_FOR 取到的值将是空的。

The core module supports built-in variables, whose names correspond with the names of variables in Apache.First of all, there are the variables, which represent the lines of the title of the client request, for example, $http_user_agent, $http_cookie, and so forth.

Furthermore, there are other variables:

$arg_PARAMETER
This variable contains the value of the GET request variable PARAMETER if present in the query string

$args
This variable is equal to arguments in the line of request;

$binary_remote_addr
The address of the client in binary form;

$body_bytes_sent

$content_length
This variable is equal to line Content-Length in the header of request;

$content_type
This variable is equal to line Content-Type in the header of request;

$cookie_COOKIE
The value of the cookie COOKIE;

$document_root
This variable is equal to the value of directive root for the current request;

$document_uri
The same as $uri.

$host
This variable is equal to line Host in the header of request or name of the server processing the request if the Host header is not available.

This variable may have a different value from $http_host when the Host input header is absent or has an empty value.

$http_HEADER
The value of the HTTP header HEADER when converted to lowercase and with ‘dashes’ converted to ‘underscores’, e.g. $http_user_agent, $http_referer…;

$is_args
Evaluates to “?” if $args is set, “” otherwise.

$limit_rate
This variable allows limiting the connection rate.

$query_string

The same as $args.

$remote_addr
The address of the client.

$remote_port
The port of the client;

$remote_user
This variable is equal to the name of user, authenticated by the Auth Basic Module;

$request_filename
This variable is equal to path to the file for the current request, formed from directives root or alias and URI request;

$request_body
This variable(0.7.58+) contains the body of the request. The significance of this variable appears in locations with directives proxy_pass or fastcgi_pass.

$request_body_file
Client request body temporary filename;

$request_completion
(undocumented)

$request_method
This variable is equal to the method of request, usually GET or POST.

Before and including 0.8.20, this variable always evaluates to the method name of the main request, not the current request if the current request is a subrequest.

$request_uri
This variable is equal to the complete initial URI together with the arguments;

$scheme
The HTTP scheme (i.e. http, https). Evaluated only on demand, for example:

rewrite ^(.+)$ $scheme://example.com$1 redirect;

$server_addr
Equal to the server address. As a rule, for obtaining the value of this variable is done one system call. In order to avoid system call, it is necessary to indicate addresses in directives listen and to use parameter bind.

$server_name
The name of the server.

$server_port
This variable is equal to the port of the server, to which the request arrived;

$server_protocol
This variable is equal to the protocol of request, usually this HTTP/1.0 or HTTP/1.1.

$uri
This variable is equal to current URI in the request, it can differ from initial, for example by internal redirects, or with the use of index it is file with internal redirects.

参考:

http://wiki.nginx.org/NginxHttpCoreModule#Variables

转自:http://www.freeoa.net/osuport/servap/nginx-inside-global-var_2709.html

Nginx 内置全局变量的更多相关文章

  1. nginx内置全局变量

    nginx内置全局变量 $args        请求中的参数; $binary_remote_addr        远程地址的二进制表示 $body_bytes_sent        已发送的消 ...

  2. nginx内置全局变量及含义

    名称        版本        说明(变量列表来源于文件 ngx_http_variables ) $args        1.0.8        请求中的参数; $binary_remo ...

  3. nginx内置变量 大全

    nginx内置变量 内置变量存放在  ngx_http_core_module 模块中,变量的命名方式和apache 服务器变量是一致的.总而言之,这些变量代表着客户端请求头的内容,例如$http_u ...

  4. 第三十九节,python内置全局变量

    vars()查看内置全局变量 以字典方式返回内置全局变量 #!/usr/bin/env python # -*- coding:utf8 -*- print(vars()) #输出 # {'__bui ...

  5. nginx内置变量总结

    nginx内置变量 2019-02-28 变量名称 变量用途 $atg_PARAMETER      客户端GET请求中   PARAMETER字段的值                        ...

  6. nginx 内置变量

    http://blog.sina.com.cn/s/articlelist_1834459124_1_1.html  nginx内置变量杂谈 http://nginx.org/en/docs/http ...

  7. (转)最新版 nginx内置变量 大全

    原文:http://www.cnphp.info/nginx-embedded-variables-lasted-version.html 在配置基于nginx服务器的网站时,必然会用到 nginx内 ...

  8. python内置全局变量

    vars()查看内置全局变量 以字典方式返回内置全局变量 #!/usr/bin/env python # -*- coding:utf8 -*- print(vars()) #输出 # {'__bui ...

  9. -e $request_filename + nginx内置变量

    -e表示只要filename存在,则为真,不管filename是什么类型,当然这里加了!就取反额外的一些-e filename 如果 filename存在,则为真-d filename 如果 file ...

随机推荐

  1. js中的各种宽高以及位置总结

    在javascript中操作dom节点让其运动的时候,常常会涉及到各种宽高以及位置坐标等概念,如果不能很好地理解这些属性所代表的意义,就不能理解js的运动原理,同时,由于这些属性概念较多,加上浏览器之 ...

  2. 制作OS X 10.10.3启动安装U盘

    http://www.cnblogs.com/Bob-wei/p/4471407.html 1.获得“Install OS X Yosemite.app” 2.准备一个8GB的U盘,用磁盘工具“抹掉” ...

  3. 通过Profiles查看create语句的执行时间消耗 (转)

    一,查看profiles的状态值   1,查看profiles是否已经打开了,默认是不打开的.   mysql> show profiles;   Empty set (0.02 sec) my ...

  4. RedHat5安装好后没有ip

    RedHat5安装好后,ifconfig查不到ip. 设置有问题.关闭虚拟机,点击下图所指,调出虚拟网络编辑器: 点击还原默认设置,应用,确定. 重启虚拟机,ifconfig,是不是查到ip了呢?

  5. 【Hadoop测试程序】编写MapReduce测试Hadoop环境

    我们使用之前搭建好的Hadoop环境,可参见: <[Hadoop环境搭建]Centos6.8搭建hadoop伪分布模式>http://www.cnblogs.com/ssslinppp/p ...

  6. 【转】libvirt kvm 虚拟机上网 – Bridge桥接

    libvirt kvm 虚拟机上网 – Bridge桥接 2013 年 7 月 3 日 / 东东东 / 暂无评论 目录 [hide] 1 Bridge桥接原理 2 在host机器配置桥接网络 2.1  ...

  7. bzoj3163: [Heoi2013]Eden的新背包问题

    Description “寄没有地址的信,这样的情绪有种距离,你放着谁的歌曲,是怎样的心心静,能不能说给我听.”失忆的Eden总想努力地回忆起过去,然而总是只能清晰地记得那种思念的感觉,却不能回忆起她 ...

  8. erlang使用leveldb

    用的是诺顿的开源库,参考url来自这里 下载 git clone git@github.com:/norton/lets.git 编译 cd lets ./rebar get-deps ./rebar ...

  9. CXF发布restful WebService的入门例子(客户端)

    上篇说了怎么用cxf发布restful webservice,由于浏览器只能对该service发送http的GET请求,所以如果想对服务器上的数据,还需要实现客户端. 客户端的实现方式有无数种...可 ...

  10. 让 SVN (TortoiseSVN)提交时忽略bin和obj目录

    2013-06-23 更新 后来我使用属性来过滤,结果反而没有效果了,之后我再次尝试使用全局忽略样式设置:*/bin */obj */packages 结果又有效果了,奇怪了. ------- 由于我 ...