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. Tortoisesvn单个文件夹checkout

  2. Linux 环境下开机自启动Oracle服务

    使用如下命令查看Oracle相关服务是否已启动: ps aux | grep ora_ #若无ora_**_**相关的进程,则oracle数据库实例未启动 netstat -tlnup | grep ...

  3. EF LEFT JON 关联查找

    var query = (from a in context.OQC_INSPECTION_SAMPLE.Where(expression).Where(a => context.OQC_INS ...

  4. Redis主从同步介绍

    Redis主从同步命令和配置项 启动主从复制:master无需任何操作,slave中使用以下任意一种开启复制功能 (1).通过配置文件启动主从复制: 在redis.conf中加入"slave ...

  5. Java-Thread

    1. 线程的创建和启动 1.1 继承Thread 在run方法里,通过this获取当前线程. 多个线程不能共享实例变量. 1.2 通过实现接口 1.2.1 实现Runable接口 在run方法里,只能 ...

  6. android学习笔记17——对话框(PopupWindow)

    PopupWindow ==> PopupWindow可创建类似对话框的窗口,使用其创建对话框窗口的操作步骤: 1.调用PopupWindow构造器构造PopupWindow对象: 2.调用Po ...

  7. WINDOWS黑客基础(6):查看文件里面的导入表

    int main(void) { HANDLE hFile = CreateFile("D:\\Shipyard.exe", GENERIC_READ, FILE_SHARE_RE ...

  8. C语言每日一题之No.3

    几天下来,感慨学习要坚持下来真的是件很难的事,本来说了每天一题,可是毕竟这是个细活,需要用心雕琢,有时候真的不能当天拿下来>_<.虽然说只是一题,却涉及到很多小细节,慢慢的琢磨直至完全摸透 ...

  9. [系统集成] Android 自动构建系统

    一.简介 android app 自动构建服务器用于自动下载app代码.自动打包.发布,要建立这样的服务器,关键要解决以下几个问题: 1. android app 自动化打包android 的打包一般 ...

  10. opacity兼容写法

    .opacity{ position: absolute; top: 0px;left: 0px; background: #000; filter:alpha(opacity=50); /* IE ...