zoukankan      html  css  js  c++  java
  • nginx常用内置变量

    以下仅列出一些常用变量,更多变量请到nginx官网查阅

    http://nginx.org/en/docs/varindex.html

    1. 从请求行中解析的变量

    以访问http://localhost:80/nginx/varindex?a=1&b=2得到的结果GET /nginx/varindex?a=1&b=2 HTTP/1.1 为例(可以在access.log日志中看到访问结果)
    
    $arg_name
    请求行中的参数,$arg_a=1,$arg_b=2,若无参数则为空字符串
    
    $is_args
    请求行中是否包含参数,若包含,则$is_args=?,否则为空字符串
    
    $args
    请求行中的全部参数,$args=a=1&b=2,若无参数则为空字符串
    
    $request
    完整的原始的请求行,GET /nginx/varindex?a=1&b=2 HTTP/1.1
    
    $request_method
    请求方法,如GET、POST
    
    $request_uri
    完整的原始请求URI,访问的URL除去域名(或IP)和port,如/nginx/varindex?a=1&b=2
    
    $document_uri/$uri
    请求规范化以后的URI,可能与$request_uri不同,值可能随请求的处理过程而改变
    
    $server_protocol
    请求的协议版本,如HTTP/1.0
    
    以上变量在配置文件中通常配合try_files指令和rewrite指令使用

    2. 从请求头中解析到的变量

    $host
    请求头的值,以下顺序获得:请求行中的host、请求头中的Host、配置文件中匹配到的server_name
    
    $remote_addr    
    客户端ip地址
    
    $remote_port    
    客户端端口
    
    $remote_user
    基本身份验证随附的用户名
    
    $http_cookie    
    Cookie请求头的值
    
    $http_user_agent    
    用户代理
    
    $cookie_name    
    Cookie中名为name的值    
    
    $http_referer    
    Http-Referer请求头的值

    3. 其他变量

    $cookie_name
    名为name的cookie
    
    $protocol
    与客户端通信的协议: TCP或UDP(1.11.4)
    
    $hostname
    运行nginx的服务器主机名
    
    $server_name
    接受请求的服务器主机名
    
    $body_bytes_sent
    发送给客户端的字节数
    
    $connection_requests
    通过连接发出的当前请求数
    
    $limit_rate
    用于设置响应的速度限制
    
    $time_local
    通用日志格式的本地时间
    
    $status
    响应状态返回码
    
    $request_time    
    请求处理时间
    
    $proxy_add_x_fowarded_for
    在客户端传递来的X-Forwarded-For请求头后面追加$remote_addr(用逗号分隔)
    如果客户端没有传递X-Forwarded-For请求头,那么该变量等于$remote_addr
    
    $msec
    以毫秒为单位的当前时间
    
    $scheme
    请求模式,http或https
    
    $nginx_version
    Nginx版本
    
    $pid
    工作进程的PID
  • 相关阅读:
    java的replace和replaceAll
    hibernate必须的包下载以及各个包的作用
    Jquery退出循环
    JQuery解析XML数据的几个例子
    使用ajax获取servelt数据乱码
    jquery绝对路径
    LeetCode 368. Largest Divisible Subset
    LeetCode 413. Arithmetic Slices
    LeetCode 474. Ones and Zeroes
    LeetCode 486. Predict the Winner
  • 原文地址:https://www.cnblogs.com/gudanaimei/p/13182566.html
Copyright © 2011-2022 走看看