openresty动态转发

        location /lua {
            resolver 114.114.114.114;
            content_by_lua_block {
                local args,error = ngx.req.get_uri_args()
                local adcode = args['adcode']
                local version = args['version']
                ngx.say('adcode--->',adcode)
                ngx.say('version--->',version)
                local http = require("resty.http")
                local httpc = http.new()
                local url = nil
                if version and adcode then
                    url = "http://127.0.0.1/?adcode="..adcode.."&".."version="..version
                    ngx.say(url)
                    return
                end
                local response, error = httpc:request_uri(url, {
                    method = "GET",
                    path = "/",
                    headers = {
                        ["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"
                    }
                })
                if not response then
                    ngx.say(11111111111 .. error)
                    return
                end
                ngx.status = response.status
                for k, v in pairs(response.headers) do
                    if k ~= "Transfer-Encoding" and k ~= "Connection" then
                        ngx.header[k] = v
                    end
                end
                ngx.say(response.body)
                httpc:close()
            }
        }

 

上一篇:Day15


下一篇:ftp 报错收集