设为首页 收藏本站
查看: 350|回复: 0

[经验分享] Nginx的一些内置变量

[复制链接]

尚未签到

发表于 2016-12-25 11:21:28 | 显示全部楼层 |阅读模式
HTTP核心模块支持一些内置变量,变量名与apache里的对应。比如 $http_user_agent,$http_cookie等表示HTTP请求信息的变量。
更多变量:
$args, 请求中的参数;

$content_length, HTTP请求信息里的"Content-Length";

$content_type, 请求信息里的"Content-Type";

$document_root, 针对当前请求的根路径设置值;

$document_uri, 与$uri相同;

$host, 请求信息中的"Host",如果请求中没有Host行,则等于设置的服务器名;

$limit_rate, 对连接速率的限制;

$request_method, 请求的方法,比如"GET"、"POST"等;

$remote_addr, 客户端地址;

$remote_port, 客户端端口号;

$remote_user, 客户端用户名,认证用;

$request_filename, 当前请求的文件路径名

$request_body_file, ??

$request_uri, 请求的URI,带参数;

$query_string, 与$args相同;

$scheme, 所用的协议,比如http或者是https,比如rewrite ^(.+)$ $scheme://example.com$1 redirect;

$server_protocol, 请求的协议版本,"HTTP/1.0"或"HTTP/1.1";

$server_addr, 服务器地址,如果没有用listen指明服务器地址,使用这个变量将发起一次系统调用以取得地址(造成资源浪费);

$server_name, 请求到达的服务器名;

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

$uri, 请求的URI,可能和最初的值有不同,比如经过重定向之类的。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/iinel/archive/2009/07/04/4321383.aspx


nginx系统变量列表来自nginx wiki

The module ngx_http_core_module supports the built-in variables, whose names correspond with the names of variables in Apache.

First of all, these 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;

$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;

$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, to whom the request arrived, if there is no this line;

$is_args evaluates to “?” if $args is set, “” otherwise.

$limit_rate, the variable allows to limit connection rate;

$query_string, the same as $args;

$request_method, this variable is equal to the method of request, usually this “GET” or “POST”;

$remote_addr, this variable is equal to the address of client;

$remote_port, this variable is equal to the port of client;

$remote_user, this variable is equal to the name of user, authenticated by ngx_http_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_file, client request body temporary filename;

$request_uri, this variable is equal to the complete initial URI together with the arguments;

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

rewrite ^(.+)$ $scheme://example.com$1 redirect;
$server_protocol, this variable is equal to the protocol of request, usually this “HTTP/1.0″ or “HTTP/1.1″;

$server_addr, the variable is equal to the server address, to whom arrived the request. 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, this variable is equal to the name of the server, to whom arrived the request;

$server_port, this variable is equal to the port of the server, to which the request arrived;

$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://hi.baidu.com/chiron2012/item/6c8d4711a34d449698ce3375

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-319154-1-1.html 上篇帖子: Nginx配置文件解析之二 下篇帖子: memcached+nginx+tomcat 负债均衡
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表