通过高性能网关OpenResty鉴权

zhx1994
zhx1994 2019-11-15 18:03
阅读需:0

        1.要先安装OpenResty的环境,安装地址 http://openresty.org/cn/installation.html

        2.配置nginx.conf

        location ^~ /business/ {

            default_type application/json;

            rewrite_by_lua_file /zzserver/acm/nginx/lua-code/error-service.lua;

            access_by_lua_file /zzserver/acm/nginx/lua-code/tr-jwt-auth.lua;

            proxy_pass http://localhost:8316/business/;

            body_filter_by_lua_file /zzserver/acm/nginx/lua-code/post-handle-body.lua;

        }


        post-handle-body.lua的内容

local userAccount = ngx.header["User-Account"]
if userAccount == nil then
    userAccount = ''
end 
if ngx.status == 500 then
    ngx.log(ngx.ERR, "failed request on current user:" .. userAccount)
elseif ngx.status == 409 then
    local resp_body = string.sub(ngx.arg[1], 11000)
    ngx.log(ngx.ERR, "conflict request on current user:" .. userAccount .. "======response body:" .. resp_body)
end

       tr-jwt-auth.lua的内容

local userAccount = ngx.header["User-Account"]
if userAccount == nil then
    userAccount = ''
end 
if ngx.status == 500 then
    ngx.log(ngx.ERR, "failed request on current user:" .. userAccount)
elseif ngx.status == 409 then
    local resp_body = string.sub(ngx.arg[1], 11000)
    ngx.log(ngx.ERR, "conflict request on current user:" .. userAccount .. "======response body:" .. resp_body)
end


评论
  • 消灭零回复