• 欢迎访问本站,本站记录博主日常编程遇到的问题,知识,惊奇软件等。如有问题还请留言


    Deprecated: strip_tags(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/gschaos.club/wp-content/themes/Git-alpha-6h0SRk/header.php on line 294

Nginx中变量详解

nginx mysticalycc 4年前 (2021-06-29) 1138次浏览 已收录 0个评论

nginx中变量详解

一、http Croe模块

$http_user_agent客户端UA信息
$http_cookie客户端COOKIE
$cookie_name参考$arg_name的用法
$arg_name获取URI中的GET参数,比方说http://localhost:8080/test?class=3,则用$arg_class获取。注:1)不区分大小写,例如CLASS=2同样使用$arg_class获取;2)如果参数escape编码了,使用set_unescape_uri 反编码,例如: set_unescape_uri $name $arg_name; set_unescape_uri $class $arg_class; echo “name: $name”; echo “class: $class”
$args获取url中的GET参数字符串,www.129.com/?name=a1&b=b1,$args=name=a1&b=b1
$binary_remote_addr二进制格式的客户端地址,例如\xC0\xA8P\x81,表示为192.168.80.1
$body_bytes_sent响应体的大小,即使发生了中断或者是放弃,也是一样的准确。
$bytes_sentnumber of bytes sent to a client
$connectionconnection serial number
$connection_requestscurrent number of requests made through a connection
$content_length请求头部信息中的Content-Length
$content_type请求头部信息中的Content-Type
$document_root变量的值为当前请求的location(http,server,location,location中的if)中root指令中指定的值,或alias的值
$document_uri同$uri
$host该变量的值等于请求头中Host的值。如果Host无效时,那么就是处理该请求的server的名称。在下列情况中,$host变量的取值不同于$http_host变量。1) 当请求头中的Host字段未指定(使用默认值)或者为空值,那么$host等于server_name指令指定的值。 2) 当Host字段包含端口是,$host并不包含端口号。另外,从0.8.17之后的nginx中,$host的值总是小写。
$hostname有gethostname返回值设置机器名
$http_*name*该变量的值为HTTP 请求头HEADER,具体使用时会转换为小写,并且将“——”(破折号)转换为“_”(下划线)。例如$http_Connection
$httpson” if connection operates in SSL mode, or an empty string otherwise
$is_args?” if a request line has arguments, or an empty string otherwise
$limit_rate该变量允许限制连接速率,参考 limit_rate
$mseccurrent time in seconds with the milliseconds resolution (1.3.9, 1.2.6)
$nginx_version版本
$pidPid
$pipe“p” if request was pipelined, “.” otherwise (1.3.12, 1.2.7)
$query_string同$args
$realpath_rootan absolute pathname corresponding to the root or alias directive’s value for the current request, with all symbolic links resolved to real paths
$remote_addr客户端的IP地址
$remote_port客户端连接端口
$remote_user变量等于用户的名字,基本身份验证模块使用
$requestfull original request line
$request_body该变量包含了请求体的主要信息。该变量与proxy_pass或者fastcgi_pass相关
$request_body_file客户端请求体的临时文件
$request_completion如果请求成功完成,那么显示“OK”。如果请求没有完成或者请求不是该请求系列的最后一部分,那么它的值为空。
$request_filename该变量等于当前请求文件的路径,有指令root或者alias和URI构成
$request_idunique request identifier generated from 16 random bytes, in hexadecimal (1.11.0)
$request_lengthrequest length (including request line, header, and request body) (1.3.12, 1.2.7)
$request_method该变量的值通常是GET或者POST。
$request_timerequest processing time in seconds with a milliseconds resolution (1.3.9, 1.2.6); time elapsed since the first bytes were read from the client
$request_uri该变量的值等于原始的URI请求,就是说从客户端收到的参数包括了原始请求的URI,该值是不可以被修改的,不包含主机名,例如“/foo/bar.php?arg=baz”。
$scheme功能:该变量表示HTTP scheme(例如HTTP,HTTPS),根据实际使用情况来决定,例如:rewrite ^ $scheme://example.com$uri redirect;
$sent_http_*name*arbitrary response header field; the last part of a variable name is the field name converted to lower case with dashes replaced by underscores
$server_addr该变量的值等于服务器的地址。通常来说,在完成一次系统调用之后就会获取变量的值,为了避开系统钓鱼,那么必须在listen指令中使用bind参数。
$server_name该变量为server的名字。
$server_port该变量等于接收请求的端口
$server_protocol该变量的值为请求协议的值,通常是HTTP/1.0或者HTTP/1.1
$statusresponse status (1.3.2, 1.2.2)
$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_spaceinformation about the client TCP connection; available on systems that support the TCP_INFO socket option
$time_iso8601local time in the ISO 8601 standard format (1.3.12, 1.2.7)
$time_locallocal time in the Common Log Format (1.3.12, 1.2.7)
$uri该变量的值等于当前请求中的URI(没有参数,不包括$args)的值。它的值不同于request_uri,由浏览器客户端发送的request_uri的值。例如,可能会被内部重定向或者使用index。 另外需要注意:$uri不包含主机名,例如 “/foo/bar.html” 当前判断URL= $scheme://$server_name/$url

MysticalYcc , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Nginx中变量详解
喜欢 (0)
mysticalycc
关于作者:
简短的个人签名

Warning: Attempt to read property "comment_author_email" on null in /www/wwwroot/gschaos.club/wp-content/themes/Git-alpha-6h0SRk/comments.php on line 47
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到