您的位置:首页 > 运维架构 > Nginx

nginx的那些内置变量

2015-12-17 18:07 766 查看
nginx在配置文件nginx.conf中可以使用很多内置变量,配置如下:

location /info {
add_header 'Content-Type' 'text/html';
echo "http_user_agent            :$http_user_agent         <br>";
echo "http_cookie                :$http_cookie             <br>";
echo "http_user_agent            :$http_user_agent         <br>";
echo "http_cookie                :$http_cookie             <br>";
echo "arg_name                   :$arg_name                <br>";
echo "args                       :$args                    <br>";
echo "binary_remote_addr         :$binary_remote_addr      <br>";
echo "body_bytes_sent            :$body_bytes_sent         <br>";
echo "bytes_sent                 :$bytes_sent              <br>";
echo "connection                 :$connection              <br>";
echo "connection_requests        :$connection_requests     <br>";
echo "content_length             :$content_length          <br>";
echo "content_type               :$content_type            <br>";
echo "cookie_name                :$cookie_name             <br>";
echo "document_root              :$document_root           <br>";
echo "document_uri               :$document_uri            <br>";
echo "uri                        :$uri                     <br>";
echo "host                       :$host                    <br>";
echo "hostname                   :$hostname                <br>";
echo "http_name                  :$http_name               <br>";
echo "https                      :$https                   <br>";
echo "is_args                    :$is_args                 <br>";
echo "limit_rate                 :$limit_rate              <br>";
echo "msec                       :$msec                    <br>";
echo "nginx_version              :$nginx_version           <br>";
echo "pid                        :$pid                     <br>";
echo "pipe                       :$pipe                    <br>";
echo "proxy_protocol_addr        :$proxy_protocol_addr     <br>";
echo "query_string               :$query_string            <br>";
echo "realpath_root              :$realpath_root           <br>";
echo "remote_addr                :$remote_addr             <br>";
echo "remote_port                :$remote_port             <br>";
echo "remote_user                :$remote_user             <br>";
echo "request                    :$request                 <br>";
echo "request_body               :$request_body            <br>";
echo "request_body_file          :$request_body_file       <br>";
echo "request_completion         :$request_completion      <br>";
echo "request_filename           :$request_filename        <br>";
echo "request_length             :$request_length          <br>";
echo "request_method             :$request_method          <br>";
echo "request_time               :$request_time            <br>";
echo "request_uri                :$request_uri             <br>";
echo "scheme                     :$scheme                  <br>";
echo "sent_http_name             :$sent_http_name          <br>";
echo "server_addr                :$server_addr             <br>";
echo "server_name                :$server_name             <br>";
echo "server_port                :$server_port             <br>";
echo "server_protocol            :$server_protocol         <br>";
echo "status                     :$status                  <br>";
echo "tcpinfo_rtt                :$tcpinfo_rtt             <br>";
echo "tcpinfo_rttvar             :$tcpinfo_rttvar          <br>";
echo "tcpinfo_snd_cwnd           :$tcpinfo_snd_cwnd        <br>";
echo "tcpinfo_rcv_space          :$tcpinfo_rcv_space       <br>";
echo "tcpinfo_rtt                :$tcpinfo_rtt             <br>";
echo "tcpinfo_rttvar             :$tcpinfo_rttvar          <br>";
echo "tcpinfo_snd_cwnd           :$tcpinfo_snd_cwnd        <br>";
echo "tcpinfo_rcv_space          :$tcpinfo_rcv_space       <br>";
echo "tcpinfo_rtt                :$tcpinfo_rtt             <br>";
echo "tcpinfo_rttvar             :$tcpinfo_rttvar          <br>";
echo "tcpinfo_snd_cwnd           :$tcpinfo_snd_cwnd        <br>";
echo "tcpinfo_rcv_space          :$tcpinfo_rcv_space       <br>";
echo "tcpinfo_rtt                :$tcpinfo_rtt             <br>";
echo "tcpinfo_rttvar             :$tcpinfo_rttvar          <br>";
echo "tcpinfo_snd_cwnd           :$tcpinfo_snd_cwnd        <br>";
echo "tcpinfo_rcv_space          :$tcpinfo_rcv_space       <br>";
echo "time_iso8601               :$time_iso8601            <br>";
echo "time_local                 :$time_local              <br>";
echo "uri                        :$uri                     <br>";
}


  

测试结果如下:
http://127.0.0.1/info?a=1&b=2
http_user_agent :Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
http_user_agent :Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36
arg_name :
args :a=1&b=2
binary_remote_addr :�w�
body_bytes_sent :0
bytes_sent :0
connection :6
connection_requests :2
content_length :
content_type :
cookie_name :
document_root :/opt/openresty/nginx/html
document_uri :/info
uri :/info
http_name :
https :
is_args :?
limit_rate :0
msec :1450346470.512
nginx_version :1.9.3
pid :8161
pipe :.
proxy_protocol_addr :
query_string :a=1&b=2
realpath_root :/opt/openresty/nginx/html
remote_addr :127.0.0.1
remote_port :57621
remote_user :
request :GET /info?a=1&b=2 HTTP/1.1
request_body :
request_body_file :
request_completion :
request_filename :/opt/openresty/nginx/html/info
request_length :391
request_method :GET
request_time :0.000
request_uri :/info?a=1&b=2
scheme :http
sent_http_name :
server_addr :127.0.0.1
server_name :localhost
server_port :80
server_protocol :HTTP/1.1
status :200
tcpinfo_rtt :73750
tcpinfo_rttvar :99500
tcpinfo_snd_cwnd :10
tcpinfo_rcv_space :14480
tcpinfo_rtt :73750
tcpinfo_rttvar :99500
tcpinfo_snd_cwnd :10
tcpinfo_rcv_space :14480
tcpinfo_rtt :73750
tcpinfo_rttvar :99500
tcpinfo_snd_cwnd :10
tcpinfo_rcv_space :14480
tcpinfo_rtt :73750
tcpinfo_rttvar :99500
tcpinfo_snd_cwnd :10
tcpinfo_rcv_space :14480
time_iso8601 :2015-12-17T18:01:10+08:00
time_local :17/Dec/2015:18:01:10 +0800
uri :/info


参考:

http://www.cnphp.info/nginx-embedded-variables-lasted-version.html

https://openresty.org/download/agentzh-nginx-tutorials-zhcn.html

http://openresty.org/#eBooks
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: