nginx请求
- ngx.exec:nginx跳转;跳转到其他的location中执行。但仅限nginx内部的location。
- ngx.redirect:和nginx.exec相似,但支持外部跳转。
- ngx.location.capture_multi:并发请求;但仅限nginx内部的location。
- http包中multi方法:概念上与ngx.location.capture_multi相似,但支持外部接口。
读取请求参数:
POST:
1.ngx.req.read_body() -- 解析 body 参数之前一定要先读取 body
ngx.req.get_post_args()
2.get_body_data()
这两种都可以获取post参数,第二种需要开启 lua_need_request_body on或先调用ngx.req.read_body() ;
GET:
ngx.req.get_uri_args()
由于 Nginx 是为了解决负载均衡场景诞生的,所以它默认是不读取 body 的行为,会对 API Server 和 Web Application 场景造成一些影响。根据需要正确读取、丢弃 body 对 OpenResty 开发是至关重要的。
ngx.say
或 ngx.print区别:
ngx.say
会对输出响应体多输出一个 \n,两者均为异步输出