同步操作将从 小飞/proxygateway 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
local _M = {}function test_output(content, status)ngx.header.content_type = 'application/json;charset=UTF-8';ngx.say(content)ngx.status = statusngx.exit(status)endfunction split(str, delimiter)if str==nil or str=='' or delimiter==nil thenreturn nilendlocal result = {}for match in (str..delimiter):gmatch("(.-)"..delimiter) dotable.insert(result, match)endreturn resultendfunction rewrite(request_uri, reg, original_uri)i, j = string.find(request_uri, reg)if i ~= nil thenlocal real_uri, index=string.gsub(request_uri, reg, original_uri, 1)return real_uriendreturn nilendfunction _M.dispatch()local cjson = require "cjson"local cache = ngx.shared.cachelocal config_str=cache:get(ngx.var.host);if config_str == nil thenconfig_str=cache:get("localhost");if config_str == nil thenngx.exit(404)endendlocal config = cjson.decode(config_str)local real_uri = nillocal api_info = nillocal api_uri_array = config["api_uri_array"]local api_uri_map = config["api_uri_map"]local uri = ngx.var.uriif ngx.var.args ~= nil thenuri = uri.."?"..ngx.var.argsendfor k,uri_regx in pairs(api_uri_array) dolocal api_info_t = api_uri_map[uri_regx];real_uri = rewrite(uri, api_info_t["request_uri"], api_info_t["original_uri"]);if(real_uri ~= nil) thenapi_info = api_info_tbreak;endendif api_info == nil thenngx.exit(404)endlocal servers = api_info["servers"]local server_count = table.getn(servers)if server_count == 0 thenngx.exit(503)endlocal request_index_cache_key = ngx.var.host.."_request_index_"..api_info["request_uri"]local request_index = cache:get(request_index_cache_key)if request_index == nil thenrequest_index = 1endcache:set(request_index_cache_key, request_index+1)local server = servers[request_index%server_count+1];if api_info["host"] == "localhost" thenapi_info["host"] = ngx.var.hostendif server["protocol"] ~= nil and server["protocol"] ~= "" thenngx.var.upstream = server["protocol"].."servers"endngx.var.backend_host = server["ip"]ngx.var.backend_port = server["port"]ngx.var.newhost = api_info["host"]ngx.req.set_header("Host", api_info["host"])local uri_t = split(real_uri, "?")ngx.req.set_uri(uri_t[1])if table.getn(uri_t) == 2 thenlocal uri_args = uri_t[2]ngx.req.set_uri_args(uri_args)elsengx.req.set_uri_args({})endendreturn _M
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。