From c42a44be2cb83883b234816f9c894a16c321a8ba Mon Sep 17 00:00:00 2001 From: William Mantly Date: Wed, 7 Aug 2024 22:35:30 -0400 Subject: [PATCH] Fixed nginx conf issue --- ops/nginx_conf/nginx.conf | 5 +---- ops/nginx_conf/proxy.conf | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ops/nginx_conf/nginx.conf b/ops/nginx_conf/nginx.conf index e9a1f74..1fa491f 100644 --- a/ops/nginx_conf/nginx.conf +++ b/ops/nginx_conf/nginx.conf @@ -60,8 +60,6 @@ http { local res, err = red:hgetall("proxy_Host_"..domain) local res = red:array_to_hash(res) - ngx.ctx.targetInfo = res - if not res["ip"] then if connect("/var/run/proxy_lookup.socket") then assert(socket:send(json.encode({domain = domain}))) @@ -76,14 +74,13 @@ http { end end - ngx.ctx.targetInfo = res - if not res["ip"] then ngx.log(ngx.ERR, "no host found for key ", domain) ngx.exit(406) return false end + ngx.ctx.targetInfo = res ngx.ctx.toAllow = true; if res['wildcard_parent'] then diff --git a/ops/nginx_conf/proxy.conf b/ops/nginx_conf/proxy.conf index cb1ebfc..390b067 100644 --- a/ops/nginx_conf/proxy.conf +++ b/ops/nginx_conf/proxy.conf @@ -20,26 +20,33 @@ server { set $header_host $host; access_by_lua ' + local res = ngx.ctx.targetInfo + if not res then + ngx.log(ngx.ERR, "no host found for key ", domain) + ngx.exit(406) + return false + end + local host = ngx.var.host local uri = ngx.var.uri local scheme = ngx.var.scheme if scheme == "http" then - if ngx.ctx.targetInfo["forcessl"] == "true" then + if res["forcessl"] == "true" then return ngx.redirect("https://"..host..uri, 301) end end - if ngx.ctx.targetInfo["targetssl"] == "true" then + if res["targetssl"] == "true" then ngx.var.target_scheme = "https" end - if ngx.ctx.targetInfo["host-pass-though"] == "false" then - ngx.var.header_host = ngx.ctx.targetInfo["ip"] + if res["host-pass-though"] == "false" then + ngx.var.header_host = res["ip"] end - ngx.var.target = ngx.ctx.targetInfo["ip"] - ngx.var.target_port = ngx.ctx.targetInfo["targetPort"] + ngx.var.target = res["ip"] + ngx.var.target_port = res["targetPort"] ';