`
男人50
  • 浏览: 230734 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
社区版块
存档分类
最新评论

Nginx + Lua 实战

 
阅读更多
    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")            
               ';
        }
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics