内置变量存放在 ngx_http_core_module模块中,变量的命名方式和apache 服务器变量是一致的。
$arg_name
1 |
请求中的的参数名,即“?”后面的arg_name=arg_value形式的arg_name |
$args
1 |
请求中的参数值 |
$binary_remote_addr
1 |
客户端地址的二进制形式, 固定长度为4个字节 |
$body_bytes_sent
1 |
传输给客户端的字节数,响应头不计算在内;这个变量和Apache的mod_log_config模块中的“%B”参数保持兼容 |
$bytes_sent
1 |
传输给客户端的字节数 (1.3.8, 1.2.5) |
$connection
1 |
TCP连接的序列号 (1.3.8, 1.2.5) |
$connection_requests
1 |
TCP连接当前的请求数量 (1.3.8, 1.2.5) |
$content_length
1 |
“Content-Length” 请求头字段 |
$content_type
1 |
“Content-Type” 请求头字段 |
$cookie_name
1 |
cookie名称 |
$document_root
1 |
当前请求的文档根目录或别名 |
$document_uri
1 |
同 $uri |
$host
1 |
优先级如下:HTTP请求行的主机名>”HOST”请求头字段>符合请求的服务器名 |
$hostname
1 |
主机名 |
$http_name
1 |
匹配任意请求头字段; 变量名中的后半部分“name”可以替换成任意请求头字段,如在配置文件中需要获取http请求头:“Accept-Language”,那么将“-”替换为下划线,大写字母替换为小写,形如:$http_accept_language即可。 |
$https
1 |
如果开启了SSL安全模式,值为“on”,否则为空字符串。 |
$is_args
1 |
如果请求中有参数,值为“?”,否则为空字符串。 |
$limit_rate
1 |
用于设置响应的速度限制,详见 limit_rate。 |
$msec
1 |
当前的Unix时间戳 (1.3.9, 1.2.6) |
$nginx_version
1 |
nginx版本 |
$pid
1 |
工作进程的PID |
$pipe
1 |
如果请求来自管道通信,值为“p”,否则为“.” (1.3.12, 1.2.7) |
$proxy_protocol_addr
1 |
获取代理访问服务器的客户端地址,如果是直接访问,该值为空字符串。(1.5.12) |
$query_string
1 |
同 $args |
$realpath_root
1 |
当前请求的文档根目录或别名的真实路径,会将所有符号连接转换为真实路径。 |
$remote_addr
1 |
客户端地址 |
$remote_port
1 |
客户端端口 |
$remote_user
1 |
用于HTTP基础认证服务的用户名 |
$request
1 |
代表客户端的请求地址 |
$request_body
1 2 |
客户端的请求主体 此变量可在location中使用,将请求主体通过proxy_pass, fastcgi_pass, uwsgi_pass, 和 scgi_pass传递给下一级的代理服务器。 |
$request_body_file
1 |
将客户端请求主体保存在临时文件中。文件处理结束后,此文件需删除。如果需要之一开启此功能,需要设置client_body_in_file_only。如果将次文件传递给后端的代理服务器,需要禁用request body,即设置proxy_pass_request_body off,fastcgi_pass_request_body off, uwsgi_pass_request_body off, or scgi_pass_request_body off 。 |
$request_completion
1 |
如果请求成功,值为”OK”,如果请求未完成或者请求不是一个范围请求的最后一部分,则为空。 |
$request_filename
1 |
当前连接请求的文件路径,由root或alias指令与URI请求生成。 |
$request_length
1 |
请求的长度 (包括请求的地址, http请求头和请求主体) (1.3.12, 1.2.7) |
$request_method
1 |
HTTP请求方法,通常为“GET”或“POST” |
$request_time
1 |
处理客户端请求使用的时间 (1.3.9, 1.2.6); 从读取客户端的第一个字节开始计时。 |
$request_uri
1 |
这个变量等于包含一些客户端请求参数的原始URI,它无法修改,请查看$uri更改或重写URI,不包含主机名,例如:”/cnphp/test.php?arg=freemouse”。 |
$scheme
1 |
请求使用的Web协议, “http” 或 “https” |
$sent_http_name
1 |
可以设置任意http响应头字段; 变量名中的后半部分“name”可以替换成任意响应头字段,如需要设置响应头Content-length,那么将“-”替换为下划线,大写字母替换为小写,形如:$sent_http_content_length 4096即可。 |
$server_addr
1 |
服务器端地址,需要注意的是:为了避免访问linux系统内核,应将ip地址提前设置在配置文件中。 |
$server_name
1 |
服务器名,www.cnphp.info |
$server_port
1 |
服务器端口 |
$server_protocol
1 |
服务器的HTTP版本, 通常为 “HTTP/1.0” 或 “HTTP/1.1” |
$status
1 |
HTTP响应代码 (1.3.2, 1.2.2) |
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space
1 |
客户端TCP连接的具体信息 |
$time_iso8601
1 |
服务器时间的ISO 8610格式 (1.3.12, 1.2.7) |
$time_local
1 |
服务器时间(LOG Format 格式) (1.3.12, 1.2.7) |
$uri
1 |
请求中的当前URI(不带请求参数,参数位于$args),可以不同于浏览器传递的$request_uri的值,它可以通过内部重定向,或者使用index指令进行修改,$uri不包含主机名,如”/foo/bar.html”。 |
nginx内置全局变量及含义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
名称 版本 说明(变量列表来源于文件 ngx_http_variables ) $args 1.0.8 请求中的参数; $binary_remote_addr 1.0.8 远程地址的二进制表示 $body_bytes_sent 1.0.8 已发送的消息体字节数 $content_length 1.0.8 HTTP请求信息里的"Content-Length"; $content_type 1.0.8 请求信息里的"Content-Type"; $document_root 1.0.8 针对当前请求的根路径设置值; $document_uri 1.0.8 与$uri相同; 比如 /test1/test2/test.php $host 1.0.8 请求信息中的"Host",如果请求中没有Host行,则等于设置的服务器名; $hostname 1.0.8 $http_cookie 1.0.8 cookie 信息 $http_post 1.0.8 $http_referer 1.0.8 引用地址 $http_user_agent 1.0.8 客户端代理信息 $http_via 1.0.8 最后一个访问服务器的Ip地址。 $http_x_forwarded_for 1.0.8 相当于网络访问路径。 $is_args 1.0.8 $limit_rate 1.0.8 对连接速率的限制; $nginx_version 1.0.8 $pid 1.0.8 $query_string 1.0.8 与$args相同; $realpath_root 1.0.8 $remote_addr 1.0.8 客户端地址; $remote_port 1.0.8 客户端端口号; $remote_user 1.0.8 客户端用户名,认证用; $request 1.0.8 用户请求 $request_body 1.0.8 $request_body_file 1.0.8 发往后端的本地文件名称 $request_completion 1.0.8 $request_filename 1.0.8 当前请求的文件路径名,比如$request_filename:D:\nginx/html/test1/test2/test.php $request_method 1.0.8 请求的方法,比如"GET"、"POST"等; $request_uri 1.0.8 请求的URI,带参数; 比如http://localhost:88/test1/test2/test.php $scheme 1.0.8 所用的协议,比如http或者是https,比如rewrite^(.+)$$scheme://example.com$1redirect; $sent_http_cache_control 1.0.8 $sent_http_connection 1.0.8 $sent_http_content_length 1.0.8 $sent_http_content_type 1.0.8 $sent_http_keep_alive 1.0.8 $sent_http_last_modified 1.0.8 $sent_http_location 1.0.8 $sent_http_transfer_encoding 1.0.8 $server_addr 1.0.8 服务器地址,如果没有用listen指明服务器地址,使用这个变量将发起一次系统调用以取得地址(造成资源浪费); $server_name 1.0.8 请求到达的服务器名; $server_port 1.0.8 请求到达的服务器端口号; $server_protocol 1.0.8 请求的协议版本,"HTTP/1.0"或"HTTP/1.1"; $uri 1.0.8 请求的URI,可能和最初的值有不同,比如经过重定向之类的。 |
2017年08月07日 15:55 沙发
学习了 欢迎互访!
2017年08月07日 18:06 1层
@剪板机 小万的随性笔记长期更新shopex产品相关文章以及日常工作中服务器、代码相关的日常笔记,感谢您的关注,欢迎常来逛逛~~