Updated nginx files
This commit is contained in:
+56
-89
@@ -1,5 +1,5 @@
|
||||
#user nobody;
|
||||
worker_processes 4;
|
||||
worker_processes 8;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
@@ -9,116 +9,83 @@ worker_processes 4;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
client_max_body_size 4g;
|
||||
client_max_body_size 4g;
|
||||
|
||||
lua_shared_dict auto_ssl 100m;
|
||||
lua_shared_dict auto_ssl_settings 64k;
|
||||
|
||||
lua_shared_dict auto_ssl 100m;
|
||||
lua_shared_dict auto_ssl_settings 64k;
|
||||
resolver 8.8.4.4 8.8.8.8;
|
||||
|
||||
resolver 8.8.4.4 8.8.8.8;
|
||||
init_by_lua_block {
|
||||
|
||||
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("allow_domain", function(domain)
|
||||
local json = require "cjson"
|
||||
local socket = assert(require "socket.unix"())
|
||||
local function connect(path)
|
||||
assert(socket:settimeout(.1))
|
||||
local status,err = pcall(function() assert(socket:connect(path)) end)
|
||||
if status then return true end
|
||||
return false
|
||||
end
|
||||
auto_ssl = (require "resty.auto-ssl").new()
|
||||
auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis")
|
||||
|
||||
local targetInfo = require "targetinfo"
|
||||
|
||||
if not domain then
|
||||
ngx.log(ngx.ERR, "no host header found")
|
||||
ngx.exit(499)
|
||||
return false
|
||||
end
|
||||
auto_ssl:set("allow_domain", function(domain)
|
||||
ngx.log(ngx.ERR, "!!!!!!!!!! allow_domain ", ngx.ctx.toAllow)
|
||||
return ngx.ctx.toAllow
|
||||
end)
|
||||
|
||||
local redis = require "resty.redis"
|
||||
local red = redis:new()
|
||||
auto_ssl:set("request_domain", function(ssl, ssl_options)
|
||||
local domain, err = ssl.server_name()
|
||||
|
||||
red:set_timeout(1000) -- 1 second
|
||||
local res = targetInfo.get(ngx, domain, ngx.ctx.targetInfo)
|
||||
|
||||
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)
|
||||
end
|
||||
if res['wildcard_parent'] then
|
||||
return res['wildcard_parent'], err
|
||||
end
|
||||
|
||||
local res, err = red:hgetall("proxy_host_"..domain)
|
||||
local res = red:array_to_hash(res)
|
||||
return domain, err
|
||||
end)
|
||||
|
||||
if not res["ip"] then
|
||||
if connect("/var/run/proxy_lookup.socket") then
|
||||
assert(socket:send(json.encode({domain = domain})))
|
||||
while 1 do
|
||||
local s, status, partial = socket:receive()
|
||||
if partial then
|
||||
res = json.decode(partial)
|
||||
socket:close()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
auto_ssl:init()
|
||||
}
|
||||
|
||||
if not res["ip"] then
|
||||
ngx.log(ngx.ERR, "no host found for key ", domain)
|
||||
-- ngx.exit(406)
|
||||
return false
|
||||
end
|
||||
init_worker_by_lua_block {
|
||||
auto_ssl:init_worker()
|
||||
}
|
||||
|
||||
return true
|
||||
end)
|
||||
auto_ssl:init()
|
||||
}
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
|
||||
init_worker_by_lua_block {
|
||||
auto_ssl:init_worker()
|
||||
}
|
||||
server {
|
||||
listen 127.0.0.1:8999;
|
||||
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
# Increase the body buffer size, to ensure the internal POSTs can always
|
||||
# parse the full POST contents into memory.
|
||||
client_body_buffer_size 128k;
|
||||
client_max_body_size 128k;
|
||||
|
||||
server {
|
||||
listen 127.0.0.1:8999;
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
auto_ssl:hook_server()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Increase the body buffer size, to ensure the internal POSTs can always
|
||||
# parse the full POST contents into memory.
|
||||
client_body_buffer_size 128k;
|
||||
client_max_body_size 128k;
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
location / {
|
||||
content_by_lua_block {
|
||||
auto_ssl:hook_server()
|
||||
}
|
||||
}
|
||||
}
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
include mime.types;
|
||||
default_type application/octet-stream;
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
# '$status $body_bytes_sent "$http_referer" '
|
||||
# '"$http_user_agent" "$http_x_forwarded_for"';
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
gzip on;
|
||||
include sites-enabled/*;
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
include sites-enabled/*;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user