变量名 | 说明 | 备注 |
---|---|---|
$host | 请求中的主机头(Host)字段 | 如果请求中的主机头不可用或为空,则为处理请求的server名称(处理请求的server的server_name指令的值)。值为小写,不包含端口。 |
$server_name | 服务器名称 | nginx conf文件Server模块中定义的值 |
$server_port | 服务器端的端口号 | eg: 80、8080、443 |
$remote_port | 客户端的端口 | |
$remote_addr | 客户端的IP地址 | |
$$binary_remote_addr | 二进制码形式的客户端地址 | |
$document_root | 当前请求在root指令中指定的值 | |
$scheme | 协议 | eg: http、https |
$cookie_COOKIE | cookie中COOKIE的值 | eg: $cookie_iploc |
$http_HEADER | 匹配任意请求头字段 | “HEADER”可以替换成任意请求头字段,如在配置文件中需要获取http请求头:“Accept-Language”,那么将“-”替换为下划线,大写字母替换为小写,形如:$http_accept_language即可。 |
$sent_http_HEADER | HTTP响应头中的内容,HEADER为HTTP响应中的内容转为小写,-变为_(破折号变为下划线) | eg: $sent_http_cache_control、$sent_http_content_type |
$request_uri | 请求参数的原始URI | 无法修改,请查看$uri更改或重写URI |
$uri | 请求中的当前URI(不带请求参数,参数位于$args) | 不同于浏览器传递的$request_uri的值,它可以通过内部重定向,或者使用index指令进行修改。不包括协议和主机名,例如/foo/bar.html |
$document_uri | 与$uri相同 | |
$args | GET请求中的参数 | eg: foo=123&bar=abc; |
$arg_name | 请求中参数name的值 | |
$query_string | 与$args相同 | |
$arg_PARAMETER | GET请求中变量名PARAMETER参数的值 | |
$http_referer | 引导用户代理到当前页的前一页的地址信息 | |
$http_x_forwarded-for | 表示 HTTP 请求端真实 IP | X-Forwarded-For格式:X-Forwarded-For: client, proxy1, proxy2 XFF的内容由「英文逗号+空格」隔开的多个部分组成,第一个IP是离服务端最远的设备IP,然后是每一级代理的IP |
- 通常情况下:$request_uri=$document_uri($uri)+$query_string($args)
- eg: http://localhost:8080/test1/test2/index.php?a=1&b=2&c=3
1
2
3
4
5
6
7
8 >$server_port:8080
>$request_uri:/test1/test2/index.php?a=1&b=2&c=3
>$document_uri:/test1/test2/index.php
>$query_string: a=1&b=2&c=3
>$uri: /test1/test2/index.php
>$args: a=1&b=2&c=3
>$document_root:/usr/local/nginx/html
>$request_filename:/usr/local/nginx/html/test1/test2/index.php