`
xusl8888
  • 浏览: 10646 次
社区版块
存档分类
最新评论

Nginx 全局变量整理

阅读更多
Variables
The core module supports built-in variables, whose names correspond with the names of variables in Apache.

First of all, there are variables which represent header lines in the client request, for example, $http_user_agent, $http_cookie, and so forth. Note that because these correspond to what the client actually sends, they are not guaranteed to exist and their meaning is defined elsewhere (e.g. in relevant standards).

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 the GET parameters in request line, e.g. foo=123&bar=blahblah; This variable could be changed.

$binary_remote_addr
The address of the client in binary form;

$body_bytes_sent
The amount of bytes sent as part of the body of the response. Is accurate even when connections are aborted or interrupted.

$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 in such cases: 1) when the Host input header is absent or has an empty value, $host equals to the value of server_name directive; 2)when the value of Host contains port number, $host doesn't include that port number. $host's value is always lowercase since 0.8.17.

$hostname
Set to the machine's hostname as returned by gethostname

$http_HEADER
The value of the HTTP request 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.

$nginx_version
The version of Nginx that the server is currently running;

$query_string
The same as $args except that this variable is readonly.

$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
Set to "OK" if request was completed successfully. Empty if request was not completed or if request was not the last part of a series of range requests.

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

This variable always evaluates to the method name of the main request, not the current request, when the current request is a subrequest.

$request_uri
This variable is equal to the *original* request URI as received from the client including the args. It cannot be modified. Look at $uri for the post-rewrite/altered URI. Does not include host name. Example: "/foo/bar.php?arg=baz"

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

rewrite  ^  $scheme://example.com$uri  redirect;
$sent_http_HEADER
The value of the HTTP response header HEADER when converted to lowercase and with 'dashes' converted to 'underscores', e.g. $sent_http_cache_control, $sent_http_content_type... .

$server_addr
The server address. Generally nginx makes a system call to obtain this value. To improve efficiency and avoid this system call, specify an address with the listen directive and to use the bind parameter.

$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 the protocol of the request. Common examples are: HTTP/1.0 or HTTP/1.1

$uri
This variable is the current request URI, without any arguments (see $args for those). This variable will reflect any modifications done so far by internal redirects or the index module. Note this may be different from $request_uri, as $request_uri is what was originally sent by the browser before any such modifications. Does not include the protocol or host name. Example: /foo/bar.html


$args 此变量与请求行中的参数相等

$content_length 等于请求行的“Content_Length”的值。

$content_type 等同与请求头部的”Content_Type”的值

$document_root 等同于当前请求的root指令指定的值

$document_uri 与$uri一样

$host 与请求头部中“Host”行指定的值或是request到达的server的名字(没有Host行)一样

$limit_rate 允许限制的连接速率

$request_method 等同于request的method,通常是“GET”或“POST”

$remote_addr 客户端ip

$remote_port 客户端port

$remote_user 等同于用户名,由ngx_http_auth_basic_module认证

$request_filename 当前请求的文件的路径名,由root或alias和URI request组合而成

$request_body_file

$request_uri 含有参数的完整的初始URI

$query_string 与$args一样

$server_protocol 等同于request的协议,使用“HTTP/1.0”或“HTTP/1.1”

$server_addr request到达的server的ip,一般获得此变量的值的目的是进行系统调用。为了避免系统调用,有必要在listen指令中指明ip,并使用bind参数。

$server_name 请求到达的服务器名

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

$uri 等同于当前request中的URI,可不同于初始值,例如内部重定向时或使用index

参考地址:http://wiki.nginx.org/NginxHttpCoreModule#Variables
0
0
分享到:
评论

相关推荐

    nginx全局变量整理小结

    nginx全局变量整理小结,方便需要的朋友

    Nginx中全局变量整理小结

    对于Nginx下全局变量整理,方便使用Nginx的朋友调用全局变量。

    nginx内置变量

    nginx内置变量文档, 网上收集出来的

    nginx自定义变量与内置预定义变量的使用

    总览 nginx可以使用变量简化配置与提高配置的灵活性,所有的变量值都可以通过这种方式引用: ...nginx变量的一个有趣的特性就是nginx中没一个变量都是全局可见的,而他们又不是全局变量。比如下面这个例子 location

    Nginx内置变量列表

    nginx内置变量列表,根据 Nginx 源码文件 ngx_http_variables.c 提取了nginx 的内置变量。

    nginx 内置变量详解及隔离进行简单的拦截

    1,nginx内置变量 nginx 有很多内置变量可以进行简单的过滤。 $arg_name 请求行中的name参数。 $args 请求行中参数字符串。 $cookie_name 名为name的cookie。 与$uri相同。 $http_name 任意请求头的值;变量名的后...

    Nginx常见问题整理

    Nginx常见问题整理

    Nginx配置[整理].pdf

    Nginx配置[整理].pdf

    nginx 内置变量表 Excel版.rar

    经常需要配置Nginx ,其中有许多以 $ 开头的变量,经常需要查阅nginx 所支持的变量。 可能是对 Ngixn资源不熟悉,干脆就直接读源码,分析出支持的变量。 Nginx支持的http变量实现在 ngx_http_variables.c 的 ngx_...

    NGINX conf 配置文件中的变量大全

    一个NGINX conf 配置文件中的变量大全

    nginx相关配置整理

    nginx 相对 apache 的优点: 轻量级,同样起web 服务,比apache 占用更少的内存及资源 抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能 高度模块化的设计...

    nginx配置包整理

    tar包: nginx-1.2.8 openssl-1.0.1c pcre-8.37 php-5.6.23 zlib-1.2.8 亲测可兼容,可用,搭建环境CentOS6.5 步骤可参考blog

    nginx部署整理http版本

    nginx部署的步骤整理

    nginx.conf

    user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events {  worker_connections 1024; } http {  include /etc/nginx/mime.types;  default_type ...

    nginx汇总整理及安装包.rar

    nginx汇总整理及安装包,linux-windows安装包都有。。

    分享最新版 nginx内置变量 大全

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

    Nginx整理视频学习资料

    个人整理的Nginx整理视频学习资料视频,内容丰富,供大家学习.大家相互帮助

Global site tag (gtag.js) - Google Analytics