lua_package_path "/usr/local/share/luajit-2.0.2/jit?.lua;;";
lua_shared_dict devicedb 45m;
location /query {
default_type 'text/plain';
content_by_lua '
local args = ngx.req.get_uri_args()
local devicetype = args["device"]
local devicedb = ngx.shared.devicedb
local res = devicedb:get(devicetype)
ngx.say(res)
';
}
location /update {
default_type 'text/plain';
content_by_lua '
local devicedb = ngx.shared.devicedb
for item in io.lines("/usr/local/nginx-1.4.2/data/rule.txt") do
_,_,device_type, device_rule = string.find(item, "^(%a+)--(%a+)$")
devicedb:set(device_type,device_rule)
end
ngx.say("ok")
';
}
Nginx + Lua 实战
最新推荐文章于 2025-05-30 17:00:53 发布
本文介绍如何使用Nginx结合Lua来实现设备类型的规则动态更新及查询功能。通过设置Lua共享字典存储设备类型及其对应的规则,并利用Lua脚本读取文件中的配置来动态更新这些规则。
6969

被折叠的 条评论
为什么被折叠?



