nginx查看变量值

  • nginx查看变量值
location / {
        echo $host; #域名
        echo $remote_addr;
        echo $remote_user;
        echo $time_local;
        echo $request;
        echo $status;
        echo $body_bytes_sent;
        echo $http_referer;
        echo $http_user_agent;
        echo $http_x_forwarded_for;
echo $proxy_add_x_forwarded_for; }
  • 说明
echo $host; #域名
echo $remote_addr; #客户端ip 如果有代理就是代理ip
echo $remote_user; #
echo $time_local;  #时间
echo $request;     #请求方法
echo $status;      #状态
echo $body_bytes_sent;  #响应字节数
echo $http_referer;   #referer
echo $http_user_agent; #浏览器
echo $http_x_forwarded_for;  #有代理的情况,这里是客户端ip
echo $proxy_add_x_forwarded_for; #代理ip 和真实ip都显示出来。 真实ip在前面
  •  nginx内置变量
nginx内置变量
        Ngx_http_core_module模块支持内置变量,他们的名字和apache的内置变量是一致的。
        首先是说明客户请求title中的行,例如$http_user_agent,$http_cookie等等。
        此外还有其它的一些变量
        $proxy_add_x_forwarded_for   #代理ip 和真实ip都显示出来。 真实ip在前面
        $http_x_forwarded_for   #真实ip
        $remote_addr客户端ip,如果有代理。这个就是代理的ip
        $document_root  # root 设置的值
        $args此变量与请求行中的参数相等
        $content_length等于请求行的“Content_Length”的值。
        $content_type等同与请求头部的”Content_Type”的值
        $document_root等同于当前请求的root指令指定的值
        $document_uri与$uri一样
        $uri等同于当前request中的URI,可不同于初始值,例如内部重定向时或使用index
        $host与请求头部中“Host”行指定的值或是request到达的server的名字(没有Host行)一样,用域名访问取的是域名,用ip访问取的是ip
        $limit_rate允许限制的连接速率
        $request_method等同于request的method,通常是“GET”或“POST”
        $remote_port客户端port
        $remote_user等同于用户名,由ngx_http_auth_basic_module认证
        $request_filename当前请求的文件的路径名,由root或alias和URI request组合而成,文件在系统的绝对路径
        $request_body_file
        $request_uri含有参数的完整的初始URI
        $query_string与$args一样
        $sheeme http模式(http,https)尽在要求是评估例如
        Rewrite ^(.+)$ $sheme://example.com$; Redirect;
        $server_protocol等同于request的协议,使用“HTTP/或“HTTP/
        $server_addr request到达的server的ip,一般获得此变量的值的目的是进行系统调用。为了避免系统调用,有必要在listen指令中指明ip,并使用bind参数。即服务器ip
        $server_name请求到达的服务器名,域名,如果用ip访问的  那就是:_
        $server_port请求到达的服务器的端口号
原文地址:https://www.cnblogs.com/hanxiaohui/p/8487934.html