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. eclipse项目里面的类有时候会莫名其妙出现很多错误

    由于eclipse的编译是基于时间戳的判断机制的.因此当你按build   all的时候有些eclipse认为时间戳没有改变的类不会被编译.因此你可以先clean一下再编译.这个时候eclipse会将 ...

  2. OData services入门----使用ASP.NET Web API描述

    http://www.cnblogs.com/muyoushui/archive/2013/01/27/2878844.html ODate 是一种应用层协议,设计它的目的在于提供一组通过HTTP的交 ...

  3. 【1-5】jQuery对象和DOM对象

    1 jQuery对象转化为DOM对象: var $cr = $("#cr");//获得jQuery对象 var cr = $cr[0];//转化为DOM对象 或者:var cr = ...

  4. linux 串口阻塞与非阻塞参数设置

    在串口设置中,有以下两个参数可以决定是否阻塞. 在打开串口时不加O_NODELAY,可用下面的第二种方法,来进行阻塞/非阻塞的设定 c_cc[VTIME] 非规范模式读取时的超时时间(单位:百毫秒), ...

  5. SQL常用方法整理

    去除字符串重复项: declare @str varchar(8000) declare @ret varchar(8000),@return varchar(8000) select @str = ...

  6. 11个实用的Apache .htaccess配置

    <IfModule mod_rewrite.c>RewriteEngine onRewriteBase /RewriteRule cat_([0-9]{1,})_([0-9]{1,})_( ...

  7. class 文件与dex文件区别 (dvm与jvm区别)及Android DVM介绍

    区别一:dvm执行的是.dex格式文件  jvm执行的是.class文件   android程序编译完之后生产.class文件,然后,dex工具会把.class文件处理成.dex文件,然后把资源文件和 ...

  8. ajax实现--技术细节详解

    ajax原理和XmlHttpRequest对象 Ajax的原理简单来说通过XmlHttpRequest对象来向服务器发异步请求,从服务器获得数据,然后用javascript来操作DOM而更新页面.这其 ...

  9. virtual修饰符

    virtual(C# 参考) virtual 关键字用于修饰方法.属性.索引器或事件声明,并使它们可以在派生类中被重写. 例如,此方法可被任何继承它的类重写. public virtual doubl ...

  10. Android四:sqllite

    1.扩展类SQLiteOpenHelper xxSQLiteHelper extends SQLiteOpenHelper public xxSQLiteHelper(Context context, ...