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. jquery显示隐藏toggle

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Oracle中的不等于号

    今天碰到一个Oracle不等于的问题,最后搜索了一下,发现下面资料,拿来跟大家分享一下   关于Oracle中的不等于号: 在Oracle中, <> != ~= ^= 都是不等于号的意思. ...

  3. java 常用集合例子

    package test; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import ...

  4. 剑指offer系列30-----删除链表中重复的节点

    [题目]在一个排序的链表中,存在重复的结点, * 请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. * 例如,链表1->2->3->3->4->4->5 ...

  5. Spring实战4:面向切面编程

    主要内容 面向切面编程的基本知识 为POJO创建切面 使用@AspectJ注解 为AspectJ的aspects注入依赖关系 在南方没有暖气的冬天,太冷了,非常想念北方有暖气的冬天.为了取暖,很多朋友 ...

  6. IE浏览器的兼容模式代码细节解读

    兼容性对于网页设计师来说非常重要.虽然最好是建立一个完全不需依赖任何网页浏览器特性或功能的网站,但是有时候这是不可能实现的.而文件兼容模式能将网页限制在某个特定版本的IE中.可以使用 X-UA-Com ...

  7. windows mobile 共享PC网络(win7)

    win7系统安装windows mobile,将设备插入底座后,设备并不能直接共享pc的网络直接上网.原来,当插入底座后,需要打开mobile设备中心,切换一下连接网络,或者打开此窗体后确定一下,即可 ...

  8. Redis简单使用方法说明

    安装 www.redis.io下载安装包tar zxvf redis.tar.gzcd redismakecd src && make install移动文件,便于管理:mkdir - ...

  9. Linux启动过程详解(转)

    启动第一步--加载BIOS当你打开计算机电源,计算机会首先加载BIOS信息,BIOS信息是如此的重要,以至于计算机必须在最开始就找到它.这是因为BIOS中包含了CPU的相关信息.设备启动顺序信息.硬盘 ...

  10. (C#) Lock - 将对象上锁,互斥多个线程,使同步。

    C# Lock 原文:http://www.dotnetperls.com/lock Locking is essential in threaded programs. It restricts c ...