1. 获取 url
来源:https://stackoverflow.com/questions/20000911/get-complete-url-using-nginx-and-lua-with-openresty
ngx.var.request_uri # 只是 url 的 path
ngx.var.host .. '/' .. ngx.var.uri #
ngx.var.scheme
ngx.var.query_string
2. 获取 body 数据
来源:https://openresty-reference.readthedocs.io/en/latest/Lua_Nginx_API/#ngxreqread_body
2.1 ngx.var.request_body
在获取body 数据之前,需要先调用函数 ngx.req.read_body()
,否则获取到的 body 数据是空的。
ngx.req.read_body()
local body = ngx.var.request_body
2.2 ngx.req.get_body_data
Note that calling this function instead of using ngx.var.request_body
or ngx.var.echo_request_body
is more efficient because it can save one dynamic memory allocation and one data copy.