Fetchs Nginx variable by Luajit with FFI way which is fast and cheap.
Compares to ngx.var.*
, performance has increased by more than five times. ^_^
Compiles the nginx c module to OpenResty:
./configure --prefix=/opt/openresty \
--add-module=/path/to/lua-var-nginx-module
Install the Lua source code, there are two ways:
luarocks install lua-resty-ngxvar
Or we can copy the source lua file to specified directory which OpenResty can load it normally.
make install LUA_LIB_DIR=/opt/openresty/lualib/
syntax: req = ngxvar.request()
Returns the request object of current request. We can cache it at your Lua code land if we try to fetch more than one variable in one request.
syntax: val = ngxvar.fetch(name, req)
Returns the Nginx variable value by name.
location /t {
content_by_lua_block {
local var = require("resty.ngxvar")
local req = var.request()
ngx.say(var.fetch("host", req))
ngx.say(var.fetch("uri", req))
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。