Updated nginx files
This commit is contained in:
+21
-54
@@ -1,5 +1,5 @@
|
||||
#user nobody;
|
||||
worker_processes 4;
|
||||
worker_processes 8;
|
||||
|
||||
#error_log logs/error.log;
|
||||
#error_log logs/error.log notice;
|
||||
@@ -12,71 +12,38 @@ events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
client_max_body_size 4g;
|
||||
|
||||
|
||||
lua_shared_dict auto_ssl 100m;
|
||||
lua_shared_dict auto_ssl_settings 64k;
|
||||
|
||||
resolver 8.8.4.4 8.8.8.8;
|
||||
|
||||
init_by_lua_block {
|
||||
|
||||
auto_ssl = (require "resty.auto-ssl").new()
|
||||
auto_ssl:set("storage_adapter", "resty.auto-ssl.storage_adapters.redis")
|
||||
|
||||
local targetInfo = require "targetinfo"
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
ngx.log(ngx.ERR, "!!!!!!!!!! allow_domain ", ngx.ctx.toAllow)
|
||||
return ngx.ctx.toAllow
|
||||
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()
|
||||
}
|
||||
|
||||
@@ -118,7 +85,7 @@ http {
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
gzip on;
|
||||
include sites-enabled/*;
|
||||
|
||||
}
|
||||
@@ -20,56 +20,13 @@ server {
|
||||
set $header_host $host;
|
||||
|
||||
access_by_lua '
|
||||
local targetInfo = require "targetinfo"
|
||||
local host = ngx.var.host
|
||||
local uri = ngx.var.uri
|
||||
local scheme = ngx.var.scheme
|
||||
local res = targetInfo.get(ngx, host, ngx.ctx.targetInfo)
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
ngx.log(ngx.ERR, "!!!!!!!!! after getTargetInfo proxy.conf ", res["ip"])
|
||||
|
||||
if scheme == "http" 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
|
||||
RestartSec=1
|
||||
User=root
|
||||
Environment="NODE_ENV=production"
|
||||
ExecStart=/usr/bin/env node /var/www/proxy/nodejs/bin/www
|
||||
|
||||
[Install]
|
||||
|
||||
Reference in New Issue
Block a user