Watch 1 Star 1 Fork 0

iresty / lua-var-nginx-moduleLuaApache-2.0

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
Fetchs Nginx variable by Luajit with FFI way which is fast and cheap. spread retract

Clone or download
Notice: Creating folder will generate an empty file .keep, because not support in Git


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. ^_^

Table of Contents


Compiles the nginx c module to OpenResty:

./configure --prefix=/opt/openresty \

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/resty/



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.

Back to TOC


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.fetch("_request")

         ngx.say(var.fetch("host", req))
         ngx.say(var.fetch("uri", req))

Back to TOC


  • support more variables.

Back to TOC

Comments ( 0 )

Sign in for post a comment