Fixed nginx conf issue
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -25,20 +26,8 @@ http {
|
||||
auto_ssl = (require "resty.auto-ssl").new()
|
||||
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)
|
||||
@@ -52,7 +41,9 @@ http {
|
||||
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)
|
||||
@@ -61,7 +52,7 @@ http {
|
||||
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)
|
||||
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/*;
|
||||
|
||||
}
|
||||
+13
-34
@@ -19,23 +19,13 @@ server {
|
||||
set $target_port '';
|
||||
set $header_host $host;
|
||||
|
||||
access_by_lua {
|
||||
|
||||
function getTargetInfo(domain, targetInfo)
|
||||
if targetInfo then
|
||||
ngx.log(ngx.ERR, "!!!!!!! getTargetInfo targetFound")
|
||||
|
||||
return targetInfo
|
||||
end
|
||||
access_by_lua '
|
||||
local host = ngx.var.host
|
||||
local uri = ngx.var.uri
|
||||
local scheme = ngx.var.scheme
|
||||
|
||||
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)
|
||||
@@ -43,13 +33,14 @@ server {
|
||||
return false
|
||||
end
|
||||
|
||||
if not domain then
|
||||
if not host then
|
||||
ngx.log(ngx.ERR, "no host header found")
|
||||
ngx.exit(499)
|
||||
return false
|
||||
return ngx.exit(499)
|
||||
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)
|
||||
@@ -58,12 +49,12 @@ server {
|
||||
return ngx.exit(598)
|
||||
end
|
||||
|
||||
local res, err = red:hgetall("proxy_Host_"..domain)
|
||||
local res, err = red:hgetall("proxy_host_"..host)
|
||||
local res = red:array_to_hash(res)
|
||||
|
||||
if not res["ip"] then
|
||||
if connect("/var/run/proxy_lookup.socket") then
|
||||
assert(socket:send(json.encode({domain = domain})))
|
||||
assert(socket:send(json.encode({domain = host})))
|
||||
while 1 do
|
||||
local s, status, partial = socket:receive()
|
||||
if partial then
|
||||
@@ -76,22 +67,10 @@ server {
|
||||
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 ", host)
|
||||
return ngx.exit(406)
|
||||
end
|
||||
|
||||
ngx.ctx.targetInfo = res
|
||||
ngx.ctx.toAllow = true;
|
||||
end
|
||||
|
||||
|
||||
local host = ngx.var.host
|
||||
local uri = ngx.var.uri
|
||||
local scheme = ngx.var.scheme
|
||||
local res = getTargetInfo(host, ngx.ctx.targetInfo)
|
||||
|
||||
|
||||
if scheme == "http" then
|
||||
if res["forcessl"] == "true" then
|
||||
return ngx.redirect("https://"..host..uri, 301)
|
||||
@@ -108,7 +87,7 @@ server {
|
||||
|
||||
ngx.var.target = res["ip"]
|
||||
ngx.var.target_port = res["targetPort"]
|
||||
}
|
||||
';
|
||||
|
||||
|
||||
resolver 192.168.1.1 ipv6=off; #8.8.4.4; # use Google's open DNS server
|
||||
|
||||
Reference in New Issue
Block a user