Fixed nginx conf issue

This commit is contained in:
2024-08-08 14:30:22 -04:00
parent 07ff3a2e39
commit c49dcafc34
2 changed files with 98 additions and 136 deletions
+17 -34
View File
@@ -1,5 +1,5 @@
#user nobody;
worker_processes 8;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
@@ -12,6 +12,7 @@ events {
worker_connections 1024;
}
http {
client_max_body_size 4g;
@@ -23,22 +24,10 @@ http {
init_by_lua_block {
auto_ssl = (require "resty.auto-ssl").new()
auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis")
auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis")
auto_ssl:set("allow_domain", function(domain)
ngx.log(ngx.ERR, "!!!!!!!! nginx.conf allow_domain !!!!!!!!!! ", domain, ngx.ctx.toAllow)
return ngx.ctx.toAllow
end)
auto_ssl:set("request_domain", function(ssl, ssl_options)
local json = require "cjson"
local redis = require "resty.redis"
local socket = assert(require "socket.unix"())
local domain, err = ssl.server_name()
ngx.log(ngx.ERR, "!!!!!! nginx.conf request_domain !!!!!!!", domain)
local function connect(path)
assert(socket:settimeout(.1))
local status,err = pcall(function() assert(socket:connect(path)) end)
@@ -47,21 +36,23 @@ http {
end
if not domain then
ngx.log(ngx.ERR, "no host header found")
ngx.exit(499)
return false
ngx.log(ngx.ERR, "no host header found")
ngx.exit(499)
return false
end
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000) -- 1 second
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.log(ngx.ERR, "failed to connect to redis: ", err)
return ngx.exit(598)
ngx.log(ngx.ERR, "failed to connect to redis: ", err)
return ngx.exit(598)
end
local res, err = red:hgetall("proxy_Host_"..domain)
local res, err = red:hgetall("proxy_host_"..domain)
local res = red:array_to_hash(res)
if not res["ip"] then
@@ -79,21 +70,13 @@ http {
end
if not res["ip"] then
ngx.say('The domain is not allowed on this server.')
ngx.exit(406)
return false
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
return res['wildcard_parent'], err
end
return domain, err
return true
end)
auto_ssl:init()
}
@@ -135,7 +118,7 @@ http {
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
#gzip on;
include sites-enabled/*;
}
}