Nginx之Embedded Variables(ngx_http_core_module)

Nginx核心模块内置变量:
# http://nginx.org/en/docs/http/ngx_http_core_module.html#variables
# The ngx_http_core_module module supports embedded variables with names matching the Apache Server variables. First of all, these are variables representing client request header fields, such as $http_user_agent, $http_cookie, and so on. Also there are other variables:
==============
$arg_name :uri中name参数值,包括(Name,NAME)
$args :参数集合
# 测试:
# server {
# location /embedded_var {
# echo "arg_name: $arg_name";
# echo "arg_age: $arg_age";
# echo "args: $args";
# }
# }
# 结果:
# arg_name: 123
# arg_age: 100
# args: name=123&age=100&class=animal
$binary_remote_addr :客户端ip地址二进制形式,echo看不到
$body_bytes_sent :发送给客户端的字节数,不包括HTTP响应头部的大小,兼容apache的%B(apache的mod_log_config模块)
$bytes_sent :发送给客户端字节数
$connection :连接序号,依次增加
$connection_requests:一个连接,请求资源的数次
$content_length :请求首部的content_length段内容
$content_type :请求首部的content_type段内容
$cookie_name :cooike的名字
$document_root :当前请求root或别名目录的绝对路径
$document_uri :当前请求的uri
$uri :当前请求的uri
# 测试:
# location /embedded_var {
# echo "document_root: $document_root";
# echo "document_uri: $document_uri";
# echo "uri: $uri";
# }
# 结果:
# document_root: /usr/local/nginx1/html
# document_uri: /embedded_var
# uri: /embedded_var
$host :匹配顺序:url中的主机名---请求首部中Host段---服务器名称
$hostname :服务器主机名称
$http_name :类似$http_XXX,插入在http首部中以http_开头的变量
$https :开启ssl模式,为on ,否则为空
$is_args :请求uri中是否有参数,有的话为?,否则为空
$limit_rate :设置此变量可以限制http响应速率
$msec :current time in seconds with the milliseconds resolution
# 测试:
# echo "host: $host";
# echo "hostname: $hostname";
# echo "http_name: $http_name";
# echo "https: $https";
# echo "is_args: $is_args";
# echo "limit_rate: $limit_rate";
# echo "msec: $msec";
# 结果:
# host: 10.0.0.254
# hostname: oela
# http_name:
# https:
# is_args: ?
# limit_rate: 0
# msec: 1487171086.441
$nginx_version:nginx版本号
$pid :工作进程的PID号
$pipe :"p" if request was pipelined,"." otherwise
$proxy_protocol_addr :代理环境下的客户端IP,否则为空
$proxy_protocol_port :代理环境下的客户端端口,否则为空
$query_string :与$args相同
$realpath_root :root目录的绝对路径
$remote_addr :客户端IP
$remote_port :客户端端口
$remote_user :基本认证的用户名
# 测试:
# { echo "nginx_version: $nginx_version";
# echo "pid: $pid";
# echo "pipe: $pipe";
# echo "proxy_protocol_addr: $proxy_protocol_addr";
# echo "proxy_protocol_port: $proxy_protocol_port";
# echo "query_string: $query_string";
# echo "realpath_root: $realpath_root";
# echo "remote_addr: $remote_addr";
# echo "remote_port: $remote_port";
# echo "remote_user: $remote_user";
# }
# 结果:
# nginx_version: 1.11.10
# pid: 12643
# pipe: .
# proxy_protocol_addr:
# proxy_protocol_port:
# query_string: name=123&age=100&class=animal
# realpath_root: /usr/local/nginx1/html
# remote_addr: 10.0.0.1
# remote_port: 50167
# remote_user:
$request :完整的原始请求
$request_body :请求body部分,可以是缓存中的数据
$request_body_file :请求body部分时时的临时文件名称
$request_completion :请求完整时为ok,否则为空
$request_filename :当前请求的文件路径是基于root与alias指令和请求的uri
$request_id :此请求的id,十六进制,随机的16字节的数
$request_length :请求的大小,包括请求行,请求头部,请求的body部分
$request_method :请求使用的方法:GET or POST
$request_time :请求完成的时间,精确到毫秒级别
$request_uri :完整的原始请求URI
# 测试
# { echo "request: $request";
# echo "request_body: $request_body";
# echo "request_body_file: $request_body_file";
# echo "request_completion: $request_completion";
# echo "request_filename: $request_filename";
# echo "request_id: $request_id";
# echo "request_length: $request_length";
# echo "request_method: $request_method";
# echo "request_time: $request_time";
# echo "request_uri: $request_uri";
# }
# 结果
# request: GET /embedded_var?name=123&age=100&class=animal HTTP/1.1
# request_body:
# request_body_file:
# request_completion:
# request_filename: /usr/local/nginx1/html/embedded_var
# request_id: 9db874486add51c755619efb10aaf5c2
# request_length: 205
# request_method: GET
# request_time: 0.000
# request_uri: /embedded_var?name=123&age=100&class=animal
$schemae :请求的scheme, http or https
$sent_http_name :类似$sent_http_XXX
$server_addr :接收客户端请求的服务器IP
$server_name :接收客户端请求的服务器名称
$server_port :接收客户端请求的服务器端口
$server_protocol :客户端请求使用的http协议,HTTP/1.0 or HTTP/1.1
$status :响应状态码
$tcpinfo_rtt :客户端tcp连接信息,RTT(Round Trip Time)由三部分组成:链路的传播时间(propagation delay)、末端系统的处理时间、
路由器缓存中的排队和处理时间(queuing delay)。
$tcpinfo_rttvar :
$tcpinfo_snd_cwnd
$tcpinfo_rcv_space
$time_iso8601 :本地时间 iso 8601标准格式
$time_local :本地时间 Common日志模式
# 测试:
# { echo "scheme: $scheme";
# echo "sent_http_name: $sent_http_name";
echo "server_addr: $server_addr";
echo "server_name: $server_name";
echo "server_port: $server_port";
echo "server_protocol: $server_protocol";
echo "status: $status";
echo "tcpinfo_rtt: $tcpinfo_rtt";
echo "tcpinfo_rttvar: $tcpinfo_rttvar";
echo "tcpinfo_snd_cwnd: $tcpinfo_snd_cwnd";
echo "tcpinfo_rcv_space: $tcpinfo_rcv_space";
echo "time_iso8601: $time_iso8601";
echo "time_local: $time_local";
# 结果:
# scheme: http
# sent_http_name:
# server_addr: 10.0.0.254
# server_name:
# server_port: 80
# server_protocol: HTTP/1.1
# status: 200
# tcpinfo_rtt: 50250
# tcpinfo_rttvar: 58750
# tcpinfo_snd_cwnd: 10
# tcpinfo_rcv_space: 14480
# time_iso8601: 2017-02-16T00:55:57+08:00
# time_local: 16/Feb/2017:00:55:57 +0800

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,902评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,037评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,978评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,867评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,763评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,104评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,565评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,236评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,379评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,313评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,363评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,034评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,637评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,719评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,952评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,371评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,948评论 2 341

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,566评论 18 139
  • Nginx简介 解决基于进程模型产生的C10K问题,请求时即使无状态连接如web服务都无法达到并发响应量级一万的现...
    魏镇坪阅读 1,982评论 0 9
  • Nginx API for Lua Introduction ngx.arg ngx.var.VARIABLE C...
    吃瓜的东阅读 5,681评论 0 5
  • 组织:中国互动出版网(http://www.china-pub.com/) RFC文档中文翻译计划(http://...
    Palomar阅读 1,554评论 0 6
  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,624评论 24 1,002