1 Star 1 Fork 1

iresty / lua-var-nginx-module

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
王院生 提交于 2019-09-10 18:47 . doc: updated example code.

lua-var-nginx-module

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

Install

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/

Method

request

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

fetch

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))
     }
 }

Back to TOC

TODO

  • support more variables.

Back to TOC

Lua
1
https://gitee.com/iresty/lua-var-nginx-module.git
git@gitee.com:iresty/lua-var-nginx-module.git
iresty
lua-var-nginx-module
lua-var-nginx-module
master

搜索帮助