Nginx中全局变量整理小结

 更新时间:2010年08月19日 22:22:15   作者:  
对于Nginx下全局变量整理,方便使用Nginx的朋友调用全局变量。

Variables

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:
Edit section: $arg_PARAMETER $arg_PARAMETER

This variable contains the value of the GET request variable PARAMETER if present in the query string
Edit section: $args $args

This variable is equal to arguments in the line of request;
Edit section: $binary_remote_addr $binary_remote_addr

The address of the client in binary form;
Edit section: $body_bytes_sent $body_bytes_sent

(undocumented)
Edit section: $content_length $content_length

This variable is equal to line Content-Length in the header of request;
Edit section: $content_type $content_type

This variable is equal to line Content-Type in the header of request;
Edit section: $cookie_COOKIE $cookie_COOKIE

The value of the cookie COOKIE;
Edit section: $document_root $document_root

This variable is equal to the value of directive root for the current request;
Edit section: $document_uri $document_uri

The same as $uri.
Edit section: $host $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.
Edit section: $http_HEADER $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…;
Edit section: $is_args $is_args

Evaluates to “?” if $args is set, “” otherwise.
Edit section: $limit_rate $limit_rate

This variable allows limiting the connection rate.
Edit section: $query_string $query_string

The same as $args.
Edit section: $remote_addr $remote_addr

The address of the client.
Edit section: $remote_port $remote_port

The port of the client;
Edit section: $remote_user $remote_user

This variable is equal to the name of user, authenticated by the Auth Basic Module;
Edit section: $request_filename $request_filename

This variable is equal to path to the file for the current request, formed from directives root or alias and URI request;
Edit section: $request_body $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.
Edit section: $request_body_file $request_body_file

Client request body temporary filename;
Edit section: $request_completion $request_completion

(undocumented)
Edit section: $request_method $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.
Edit section: $request_uri $request_uri

This variable is equal to the complete initial URI together with the arguments;
Edit section: $scheme $scheme

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

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

Edit section: $server_addr $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.
Edit section: $server_name $server_name

The name of the server.
Edit section: $server_port $server_port

This variable is equal to the port of the server, to which the request arrived;
Edit section: $server_protocol $server_protocol

This variable is equal to the protocol of request, usually this HTTP/1.0 or HTTP/1.1.
Edit section: $uri $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://www.givingtree.com.cn/entry/Nginx-Location%E5%9F%BA%E6%9C%AC%E8%AF%AD%E6%B3%95

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


$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

相关文章

  • win10系统安装Nginx的详细步骤

    win10系统安装Nginx的详细步骤

    Nginx是一款自由的、开源的、高性能的HTTP服务器和反向代理服务器,同时也提供了IMAP/POP3/SMTP服务,这篇文章主要介绍了win10系统安装Nginx的详细步骤,需要的朋友可以参考下
    2023-02-02
  • Windows下用Nginx配置https服务器及反向代理的问题

    Windows下用Nginx配置https服务器及反向代理的问题

    这篇文章主要介绍了Windows下用Nginx配置https服务器及反向代理的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-09-09
  • Nginx反向代理之proxy_redirect指令的实现

    Nginx反向代理之proxy_redirect指令的实现

    proxy_redirect指令是用来重置头信息中的"Location"和"Refresh"的值,本文就来详细的介绍一下如何使用,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-08-08
  • ubuntu中如何使用nginx监听80端口进行转发

    ubuntu中如何使用nginx监听80端口进行转发

    这篇文章主要介绍了ubuntu中如何使用nginx监听80端口进行转发问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-06-06
  • Nginx跨域设置Access-Control-Allow-Origin无效的解决办法

    Nginx跨域设置Access-Control-Allow-Origin无效的解决办法

    今天小编就为大家分享一篇关于Nginx跨域设置Access-Control-Allow-Origin无效的解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-02-02
  • WebSocket 配置与Nginx 的完美结合(过程详解)

    WebSocket 配置与Nginx 的完美结合(过程详解)

    本文详细介绍了如何在Nginx中配置WebSocket,确保其在生产环境中的性能与稳定性,从安装Nginx开始,到基本配置的设定,再到重启Nginx应用配置,同时,介绍了多种验证WebSocket配置正确性的方法,如使用浏览器的开发者工具、wscat测试工具及编写客户端代码
    2024-11-11
  • 启动Nginx.exe出现闪退问题的解决方案

    启动Nginx.exe出现闪退问题的解决方案

    在做项目时,使用老师给的代码,点击Nginx.exe出现闪退的情况,出现这个问题可能出现的情况,端口号被占用或者logs下文件路径有问题,所以本文小编给大家介绍了启动Nginx.exe出现闪退问题的解决方案,需要的朋友可以参考下
    2024-03-03
  • nginx获取真实的ip的方法

    nginx获取真实的ip的方法

    在实际应用中,我们可能需要获取用户的ip地址,比如做异地登陆的判断等等,本文主要介绍了nginx获取真实的ip的方法,具有一定的参考价值,感兴趣的可以了解一下
    2023-08-08
  • 使用Nginx实现负载均衡的策略

    使用Nginx实现负载均衡的策略

    本篇文章主要介绍了使用Nginx实现负载均衡的策略,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • 使用nginx配置访问wgcloud的方法

    使用nginx配置访问wgcloud的方法

    这篇文章主要介绍了使用nginx配置访问wgcloud的方法,在这里大家需要记得agent的配置文件项serverUrl的80端口也要写上,需要的朋友可以参考下
    2021-06-06

最新评论