nginx的 ngx.var ngx.ctx ngx.req
ngx.var 是获取 Nginx 的变量,需要经历字符串 hash、hash 表查找等过程。
ngx.ctx 仅仅是一个 Lua table 而已,它的引用存放在 ngx_lua 的模块上下文(ctx_ref)。
使用 ngx.ctx 比 ngx.var 往往是更好的选择。
https://moonbingbing.gitbooks.io/openresty-best-practices/content/openresty/inline_var.html
ngx.var的api
| 名称 | 说明 |
|---|---|
| $arg_name | 请求中的name参数 |
| $args | 请求中的参数 |
| $binary_remote_addr | 远程地址的二进制表示 |
| $body_bytes_sent | 已发送的消息体字节数 |
| $content_length | HTTP请求信息里的"Content-Length" |
| $content_type | 请求信息里的"Content-Type" |
| $document_root | 针对当前请求的根路径设置值 |
| $document_uri | 与$uri相同; 比如 /test2/test.php |
| $host | 请求信息中的"Host",如果请求中没有Host行,则等于设置的服务器名 |
| $hostname | 机器名使用 gethostname系统调用的值 |
| $http_cookie | cookie 信息 |
| $http_referer | 引用地址 |
| $http_user_agent | 客户端代理信息 |
| $http_via | 最后一个访问服务器的Ip地址。 |
| $http_x_forwarded_for | 相当于网络访问路径 |
| $is_args | 如果请求行带有参数,返回“?”,否则返回空字符串 |
| $limit_rate | 对连接速率的限制 |
| $nginx_version | 当前运行的nginx版本号 |
| $pid | worker进程的PID |
| $query_string | 与$args相同 |
| $realpath_root | 按root指令或alias指令算出的当前请求的绝对路径。其中的符号链接都会解析成真是文件路径 |
| $remote_addr | 客户端IP地址 |
| $remote_port | 客户端端口号 |
| $remote_user | 客户端用户名,认证用 |
| $request | 用户请求 |
| $request_body | 这个变量(0.7.58+)包含请求的主要信息。在使用proxy_pass或fastcgi_pass指令的location中比较有意义 |
| $request_body_file | 客户端请求主体信息的临时文件名 |
| $request_completion | 如果请求成功,设为"OK";如果请求未完成或者不是一系列请求中最后一部分则设为空 |
| $request_filename | 当前请求的文件路径名,比如/opt/nginx/www/test.php |
| $request_method | 请求的方法,比如"GET"、"POST"等 |
| $request_uri | 请求的URI,带参数 |
| $scheme | 所用的协议,比如http或者是https |
| $server_addr | 服务器地址,如果没有用listen指明服务器地址,使用这个变量将发起一次系统调用以取得地址(造成资源浪费) |
| $server_name | 请求到达的服务器名 |
| $server_port | 请求到达的服务器端口号 |
| $server_protocol | 请求的协议版本,"HTTP/1.0"或"HTTP/1.1" |
| $uri | 请求的URI,可能和最初的值有不同,比如经过重定向之类的 |
===========
ngx.var.request_uri : 是请求的url 去除 https://ip:port 的剩余部分,包含 url传递的 参数。
ngx.var.uri : 是请求的url 去除 https://ip:port 、去除 ? 问号 后面带的参数【包括逗号】,剩余的就是一些 类似 /xxx/xxx/xxx 格式的 uri 。
============
https://www.cnblogs.com/wangxusummer/p/4309007.html
ngx.req 的 api

nginx的 ngx.var ngx.ctx ngx.req的更多相关文章
- OpenResty之ngx.var.VARIABLE
1. ngx.var.VARIABLE syntax: ngx.var.VAR_NAME context: set_by_lua*, rewrite_by_lua*, access_by_lua*, ...
- ngx_lua_API 指令详解(六)ngx.thread.spawn、ngx.thread.wait、ngx.thread.kill介绍
摘要:通过lua-nginx-module中的ngx.thread同时执行多个任务. ngx_lua中访问多个第三方服务 ngx_lua中提供了ngx.socket API,可以方便的访问第三方网络服 ...
- nginx: [error] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
在重启nginx服务的时候,出现了这个错误. [root@izuf68g6a94fj32w0afx00z etc]# nginx -c /var/run/nginx/nginx.pid nginx: ...
- nginx: [emerg] mkdir() "/var/temp/nginx/client" failed (2: No such file or directory)
报错信息 [root@bogon sbin]# ./nginx nginx: [emerg] mkdir() : No such file or directory) 解决方法 [root@bogon ...
- nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied)
现象 1.centos6.9 用rpm包安装nginx 2.修改Nginx的多个配置文件和配置项 3.service nginx restart 报错: nginx: [emerg] open() & ...
- nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
测试服务器 问题描述 [root@g-s-- nginx]# /usr/sbin/nginx -c /etc/nginx/nginx.conf open() : No such file or dir ...
- nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
解决办法: nginx nginx -s reload
- 【精选】Nginx模块Lua-Nginx-Module学习笔记(一)Nginx Lua API 接口详解
源码地址:https://github.com/Tinywan/Lua-Nginx-Redis 一.介绍 各种* _by_lua,* _by_lua_block和* _by_lua_file配置指令用 ...
- 初探nginx
nginx nginx是俄罗斯人写的轻量级http服务器,Nginx 以事件驱动的方式编写,有非常好的性能,同时也是一个非常高效的反向代理.负载均衡. Nginx 稳定性高,模块库丰富,配置灵活,系统 ...
随机推荐
- 了解html标签
<title></title> 1.网页标题 2.当我们收藏网页时,默认标题就是网页标题 3.seo(搜索引擎优化) <h1></h1>~<h6& ...
- 使用ES6 Class封装的IndexDB 操作类,并实现模糊搜索
封装如下: indexDBOperate.js export class IndexDBOperate { db = null // 数据库实例 databaseName = null // 数据库 ...
- [LeetCode] 914. X of a Kind in a Deck of Cards 一副牌中的X
In a deck of cards, each card has an integer written on it. Return true if and only if you can choos ...
- [LeetCode] 913. Cat and Mouse 猫和老鼠
A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns. The grap ...
- [LeetCode] 417. Pacific Atlantic Water Flow 太平洋大西洋水流
Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...
- [LeetCode] 364. Nested List Weight Sum II 嵌套链表权重和之二
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- Oracle--SMON
一,SMON功能 a) 系统监控管理,定期合并空闲,回收临时段: b) 做实例的恢复:前滚.回滚.释放资源 二,SMON什么时候做恢复? 数据修改随时发生,但是数据同步定期做:所以会产生脏块(灰块), ...
- k8s集群-node节点设置不可调度或者删除node节点
在master 执行1, 不可调度 kubectl cordon k8s-node- kubectl uncordon k8s-node- #取消 2,驱逐已经运行的业务容器 kubectl drai ...
- etcd v3 ssl 集群添加新节点
集群搭建 下面只用同一台服务器进行三个成员节点的开启 节点1 ./etcd --name cd0 --initial-advertise-peer-urls http://127.0.0.1:2380 ...
- c# .net core + .net framework mongodb nuget 包
FastNet.Framework.Mongo https://github.com/my-core/FastNet.Framework GH.MongoDb.GenericRepository ht ...