Nginx常用变量 非常常用 $host $server_name

Nginx常用变量

测试demo

发起一次请求,地址为 http://ngxin.arg.test/a/b/c/?d=test&e=123&username=用户

GET /a/b/c/?d=test&e=123&username=%E7%94%A8%E6%88%B7 HTTP/1.1
Host: ngxin.arg.test
Connection: keep-alive
Cache-Control: max-age=0
DNT: 1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9

常用变量

名称 说明 demo值
$arg_* *可具体为请求中的某个参数 $arg_d=test
$args 请求中的参数 d=test&e=123&username=%E7%94%A8%E6%88%B7
$binary_remote_addr 远程地址的二进制表示
$body_bytes_sent 已发送的消息体字节数 0
$content_length HTTP请求信息里的"Content-Length"
$content_type 请求信息里的"Content-Type"
$document_root 针对当前请求的根路径设置值
$document_uri 与$uri相同; /a/b/c/
$host 请求信息中的"Host",如果请求中没有Host行,则等于设置的服务器名 ngxin.arg.test
$hostname 机器名使用 gethostname系统调用的值
$http_cookie cookie 信息
$http_referer 引用地址
$http_user_agent 客户端代理信息
$http_via 最后一个访问服务器的Ip地址。
$http_x_forwarded_for 相当于网络访问路径
$is_args 如果请求行带有参数,返回“?”,否则返回空字符串
$limit_rate 对连接速率的限制
$nginx_version 当前运行的nginx版本号
$pid worker进程的PID
$query_string 与$args相同
$realpath_root 按root指令或alias指令算出的当前请求的绝对路径。其中的符号链接都会解析成真实文件路径
$remote_addr 客户端IP地址
$remote_port 客户端端口号
$remote_user 客户端用户名,认证用
$request 用户请求
$request_body 这个变量(0.7.58+)包含请求的主要信息。在使用proxy_pass或fastcgi_pass指令的location中比较有意义
$request_body_file 客户端请求主体信息的临时文件名
$request_completion 如果请求成功,设为"OK";如果请求未完成或者不是一系列请求中最后一部分则设为空
$request_filename 当前请求的文件路径名,比如/opt/nginx/www/test.php
$request_method 请求的方法,比如"GET"、"POST"等
$request_uri 请求的URI,带参数 /a/b/c/?d=test&e=123&username=%E7%94%A8%E6%88%B7
$scheme 所用的协议,比如http或者是https http
$server_addr 服务器地址,如果没有用listen指明服务器地址,使用这个变量将发起一次系统调用以取得地址(造成资源浪费) 127.0.0.1
$server_name 请求到达的服务器名 ngxin.arg.test
$server_port 请求到达的服务器端口号 80
$server_protocol 请求的协议版本,“HTTP/1.0"或"HTTP/1.1” HTTP/1.1
$uri 请求的URI,可能和最初的值有不同,比如经过重定向之类的 /a/b/c/

你可能感兴趣的:(Nginx常用变量 非常常用 $host $server_name)