[PATCH compass-ci] lua_script/forward.lua: http/https request forwarding processing

Signed-off-by: cuiyili <2268260388@qq.com> --- .../lua_script/forward.lua | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 container/openresty-proxy-cache/lua_script/forward.lua diff --git a/container/openresty-proxy-cache/lua_script/forward.lua b/container/openresty-proxy-cache/lua_script/forward.lua new file mode 100755 index 0000000..bd54742 --- /dev/null +++ b/container/openresty-proxy-cache/lua_script/forward.lua @@ -0,0 +1,32 @@ +local http = require "resty.http" +local httpc = http.new() +uri = ngx.var.request_uri +host = ngx.var.http_host +if string.find(host, "11333") then + h="" +else + h="/"..host +end +path_file = "/srv/initrd/tar/"..h..uri + +local f = io.open(path_file) +if f then + url_forward = "http://127.0.0.1:80/tar/"..h..uri +else + url_forward = "http:/"..h..uri +end + +res, error = httpc:request_uri(url_forward) +if res then + ngx.status = res.status + for k, v in pairs(res.headers) do + if k ~= "Transfer-Encoding" and k ~= "Connection" then + ngx.header[k] = v + end + end + ngx.say(res.body) +else + ngx.exit(ngx.HTTP_FORBIDDEN) +end + +httpc:close() -- 2.23.0
participants (1)
-
cuiyili