Updated nginx files
This commit is contained in:
+21
-54
@@ -1,5 +1,5 @@
|
|||||||
#user nobody;
|
#user nobody;
|
||||||
worker_processes 4;
|
worker_processes 8;
|
||||||
|
|
||||||
#error_log logs/error.log;
|
#error_log logs/error.log;
|
||||||
#error_log logs/error.log notice;
|
#error_log logs/error.log notice;
|
||||||
@@ -12,71 +12,38 @@ events {
|
|||||||
worker_connections 1024;
|
worker_connections 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
http {
|
http {
|
||||||
client_max_body_size 4g;
|
client_max_body_size 4g;
|
||||||
|
|
||||||
|
|
||||||
lua_shared_dict auto_ssl 100m;
|
lua_shared_dict auto_ssl 100m;
|
||||||
lua_shared_dict auto_ssl_settings 64k;
|
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 = (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")
|
||||||
|
|
||||||
|
local targetInfo = require "targetinfo"
|
||||||
|
|
||||||
auto_ssl:set("allow_domain", function(domain)
|
auto_ssl:set("allow_domain", function(domain)
|
||||||
local json = require "cjson"
|
ngx.log(ngx.ERR, "!!!!!!!!!! allow_domain ", ngx.ctx.toAllow)
|
||||||
local socket = assert(require "socket.unix"())
|
return ngx.ctx.toAllow
|
||||||
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
|
|
||||||
|
|
||||||
if not domain then
|
|
||||||
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)
|
|
||||||
end
|
|
||||||
|
|
||||||
local res, err = red:hgetall("proxy_host_"..domain)
|
|
||||||
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})))
|
|
||||||
while 1 do
|
|
||||||
local s, status, partial = socket:receive()
|
|
||||||
if partial then
|
|
||||||
res = json.decode(partial)
|
|
||||||
socket:close()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not res["ip"] then
|
|
||||||
ngx.log(ngx.ERR, "no host found for key ", domain)
|
|
||||||
-- ngx.exit(406)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
auto_ssl:set("request_domain", function(ssl, ssl_options)
|
||||||
|
local domain, err = ssl.server_name()
|
||||||
|
|
||||||
|
local res = targetInfo.get(ngx, domain, ngx.ctx.targetInfo)
|
||||||
|
|
||||||
|
if res['wildcard_parent'] then
|
||||||
|
return res['wildcard_parent'], err
|
||||||
|
end
|
||||||
|
|
||||||
|
return domain, err
|
||||||
|
end)
|
||||||
|
|
||||||
auto_ssl:init()
|
auto_ssl:init()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +85,7 @@ http {
|
|||||||
#keepalive_timeout 0;
|
#keepalive_timeout 0;
|
||||||
keepalive_timeout 65;
|
keepalive_timeout 65;
|
||||||
|
|
||||||
#gzip on;
|
gzip on;
|
||||||
include sites-enabled/*;
|
include sites-enabled/*;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,56 +20,13 @@ server {
|
|||||||
set $header_host $host;
|
set $header_host $host;
|
||||||
|
|
||||||
access_by_lua '
|
access_by_lua '
|
||||||
|
local targetInfo = require "targetinfo"
|
||||||
local host = ngx.var.host
|
local host = ngx.var.host
|
||||||
local uri = ngx.var.uri
|
local uri = ngx.var.uri
|
||||||
local scheme = ngx.var.scheme
|
local scheme = ngx.var.scheme
|
||||||
|
local res = targetInfo.get(ngx, host, ngx.ctx.targetInfo)
|
||||||
|
|
||||||
local json = require "cjson"
|
ngx.log(ngx.ERR, "!!!!!!!!! after getTargetInfo proxy.conf ", res["ip"])
|
||||||
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
|
|
||||||
|
|
||||||
if not host then
|
|
||||||
ngx.log(ngx.ERR, "no host header found")
|
|
||||||
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)
|
|
||||||
if not ok then
|
|
||||||
ngx.log(ngx.ERR, "failed to connect to redis: ", err)
|
|
||||||
return ngx.exit(598)
|
|
||||||
end
|
|
||||||
|
|
||||||
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 = host})))
|
|
||||||
while 1 do
|
|
||||||
local s, status, partial = socket:receive()
|
|
||||||
if partial then
|
|
||||||
res = json.decode(partial)
|
|
||||||
socket:close()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not res["ip"] then
|
|
||||||
ngx.log(ngx.ERR, "no host found for key ", host)
|
|
||||||
return ngx.exit(406)
|
|
||||||
end
|
|
||||||
|
|
||||||
if scheme == "http" then
|
if scheme == "http" then
|
||||||
if res["forcessl"] == "true" then
|
if res["forcessl"] == "true" then
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
members = ['Roisin', 'Billy', 'Joseph', 'Emily', 'Chloe']
|
|
||||||
|
|
||||||
message = "I love you {}"
|
|
||||||
|
|
||||||
for member in members:
|
|
||||||
if member == "Billy":
|
|
||||||
continue
|
|
||||||
print(message.format(member))
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- Function to connect to a Unix socket
|
||||||
|
local function connect(path)
|
||||||
|
local socket = require("socket.unix")()
|
||||||
|
assert(socket:settimeout(.1))
|
||||||
|
local status, err = pcall(function() assert(socket:connect(path)) end)
|
||||||
|
if status then return true end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
print("In targetInfo module")
|
||||||
|
|
||||||
|
-- Main function of the module
|
||||||
|
function M.get(ngx, domain, targetInfo)
|
||||||
|
ngx.log(ngx.ERR, "!!!!!!!!! in targetInfo get")
|
||||||
|
if targetInfo then
|
||||||
|
return targetInfo
|
||||||
|
end
|
||||||
|
|
||||||
|
local json = require "cjson"
|
||||||
|
local redis = require "resty.redis"
|
||||||
|
|
||||||
|
if not domain then
|
||||||
|
ngx.log(ngx.ERR, "no host header found")
|
||||||
|
ngx.exit(499)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
local res, err = red:hgetall("proxy_Host_"..domain)
|
||||||
|
res = red:array_to_hash(res)
|
||||||
|
|
||||||
|
if not res["ip"] then
|
||||||
|
if connect("/var/run/proxy_lookup.socket") then
|
||||||
|
local socket = require("socket.unix")()
|
||||||
|
assert(socket:settimeout(.1))
|
||||||
|
assert(socket:connect("/var/run/proxy_lookup.socket"))
|
||||||
|
assert(socket:send(json.encode({domain = domain})))
|
||||||
|
while true do
|
||||||
|
local s, status, partial = socket:receive()
|
||||||
|
if partial then
|
||||||
|
res = json.decode(partial)
|
||||||
|
socket:close()
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not res["ip"] then
|
||||||
|
ngx.exit(406)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
ngx.ctx.targetInfo = res
|
||||||
|
ngx.ctx.toAllow = true
|
||||||
|
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
@@ -8,6 +8,7 @@ Type=simple
|
|||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=1
|
RestartSec=1
|
||||||
User=root
|
User=root
|
||||||
|
Environment="NODE_ENV=production"
|
||||||
ExecStart=/usr/bin/env node /var/www/proxy/nodejs/bin/www
|
ExecStart=/usr/bin/env node /var/www/proxy/nodejs/bin/www
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|||||||
Reference in New Issue
Block a user