Skip to content

Nginx 内置变量速查表 ​

变量说明
$args请求中的参数值
$query_string同 $args
$arg_NAMEGET 请求中 NAME 对应的值
$is_args如果请求中有参数,值为 "?",否则为空
$uri当前 URI(不带参数),可通过内部重定向修改,不包含主机名
$document_uri同 $uri
$document_root当前请求的文档根目录或 alias
$host主机名优先级:请求行主机名 > Host 请求头 > 服务器名
$hostname系统主机名
$https开启 SSL 为 on,否则为空
$binary_remote_addr客户端地址二进制形式,固定 4 字节
$body_bytes_sent发送给客户端的字节数,不含响应头
$bytes_sent发送给客户端的总字节数
$connectionTCP 连接序列号
$connection_requests当前 TCP 连接的请求数
$content_length请求头 Content-Length
$content_type请求头 Content-Type
$cookie_name对应 cookie 名称的值
$limit_rate限制响应速度
$msec当前 Unix 时间戳
$nginx_versionNginx 版本
$pid工作进程 PID
$pipe管道请求为 p,否则为 .
$proxy_protocol_addr代理协议带来的客户端地址
$realpath_root真实路径,会解析符号链接
$remote_addr客户端 IP
$remote_port客户端端口
$remote_userHTTP 基础认证用户名
$request完整请求行
$request_body请求主体内容
$request_body_file存储请求体的临时文件
$request_completion请求成功为 OK,否则为空
$request_filename当前请求对应的文件路径
$request_length请求总长度(地址+头+体)
$request_method请求方法 GET/POST 等
$request_time请求处理耗时,秒级(带毫秒精度)
$request_uri原始完整 URI(含参数),不可修改
$scheme协议 http / https
$server_addr服务器地址
$server_name服务器名称
$server_port服务器端口
$server_protocolHTTP 版本,如 HTTP/1.1
$statusHTTP 响应状态码
$time_iso8601ISO 8601 格式时间
$time_local日志格式的本地时间

请求头相关变量 ​

变量说明
$cookie_NAME客户端 Cookie 中 NAME 对应的值
$http_NAME任意请求头,如 $http_accept_language
$http_cookie完整 Cookie 头
$http_host请求中的 Host(域名/IP)
$http_referer来源页面地址
$http_user_agent客户端浏览器/设备信息
$http_x_forwarded_for透传的客户端 IP(经过代理时)

响应头相关变量 ​

变量说明
$sent_http_NAME任意响应头,如 $sent_http_content_type
$sent_http_cache_control响应头 Cache-Control
$sent_http_connectionConnection
$sent_http_content_typeContent-Type
$sent_http_keep_aliveKeep-Alive
$sent_http_last_modifiedLast-Modified
$sent_http_locationLocation
$sent_http_transfer_encodingTransfer-Encoding