-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NGINX: Remove inline Lua from template. (#11806)
- Loading branch information
Showing
30 changed files
with
361 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local balancer = require("balancer") | ||
balancer.balance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local tcp_udp_balancer = require("tcp_udp_balancer") | ||
tcp_udp_balancer.balance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local certificate = require("certificate") | ||
certificate.call() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local configuration = require("configuration") | ||
configuration.call() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local tcp_udp_configuration = require("tcp_udp_configuration") | ||
tcp_udp_configuration.call() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local tcp_udp_balancer = require("tcp_udp_balancer") | ||
tcp_udp_balancer.init_worker() |
9 changes: 9 additions & 0 deletions
9
rootfs/etc/nginx/lua/nginx/ngx_conf_is_dynamic_lb_initialized.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
local configuration = require("configuration") | ||
local backend_data = configuration.get_backends_data() | ||
if not backend_data then | ||
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR) | ||
return | ||
end | ||
|
||
ngx.say("OK") | ||
ngx.exit(ngx.HTTP_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local monitor = require("monitor") | ||
monitor.call() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
local balancer = require("balancer") | ||
local monitor = require("monitor") | ||
|
||
local luaconfig = ngx.shared.luaconfig | ||
local enablemetrics = luaconfig:get("enablemetrics") | ||
|
||
balancer.log() | ||
|
||
if enablemetrics then | ||
monitor.call() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ngx.var.cache_key = ngx.encode_base64(ngx.sha1_bin(ngx.var.tmp_cache_key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local lua_ingress = require("lua_ingress") | ||
lua_ingress.header() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
local lua_ingress = require("lua_ingress") | ||
local balancer = require("balancer") | ||
|
||
lua_ingress.rewrite() | ||
balancer.rewrite() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
local request_uri = ngx.var.request_uri | ||
local redirect_to = ngx.arg[1] | ||
|
||
local luaconfig = ngx.shared.luaconfig | ||
local use_forwarded_headers = luaconfig:get("use_forwarded_headers") | ||
|
||
if string.sub(request_uri, -1) == "/" then | ||
request_uri = string.sub(request_uri, 1, -2) | ||
end | ||
|
||
local redirectScheme = ngx.var.scheme | ||
local redirectPort = ngx.var.server_port | ||
|
||
if use_forwarded_headers then | ||
if ngx.var.http_x_forwarded_proto then | ||
redirectScheme = ngx.var.http_x_forwarded_proto | ||
end | ||
if ngx.var.http_x_forwarded_port then | ||
redirectPort = ngx.var.http_x_forwarded_port | ||
end | ||
end | ||
|
||
return string.format("%s://%s:%s%s", redirectScheme, | ||
redirect_to, redirectPort, request_uri) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
local cjson = require("cjson.safe") | ||
|
||
collectgarbage("collect") | ||
local f = io.open("/etc/nginx/lua/cfg.json", "r") | ||
local content = f:read("*a") | ||
f:close() | ||
local configfile = cjson.decode(content) | ||
|
||
local luaconfig = ngx.shared.luaconfig | ||
luaconfig:set("enablemetrics", configfile.enable_metrics) | ||
luaconfig:set("use_forwarded_headers", configfile.use_forwarded_headers) | ||
-- init modules | ||
local ok, res | ||
ok, res = pcall(require, "lua_ingress") | ||
if not ok then | ||
error("require failed: " .. tostring(res)) | ||
else | ||
lua_ingress = res | ||
lua_ingress.set_config(configfile) | ||
end | ||
ok, res = pcall(require, "configuration") | ||
if not ok then | ||
error("require failed: " .. tostring(res)) | ||
else | ||
configuration = res | ||
if not configfile.listen_ports.status_port then | ||
error("required status port not found") | ||
end | ||
configuration.prohibited_localhost_port = configfile.listen_ports.status_port | ||
end | ||
ok, res = pcall(require, "balancer") | ||
if not ok then | ||
error("require failed: " .. tostring(res)) | ||
else | ||
balancer = res | ||
end | ||
if configfile.enable_metrics then | ||
ok, res = pcall(require, "monitor") | ||
if not ok then | ||
error("require failed: " .. tostring(res)) | ||
else | ||
monitor = res | ||
end | ||
end | ||
ok, res = pcall(require, "certificate") | ||
if not ok then | ||
error("require failed: " .. tostring(res)) | ||
else | ||
certificate = res | ||
if configfile.enable_ocsp then | ||
certificate.is_ocsp_stapling_enabled = configfile.enable_ocsp | ||
end | ||
end |
Oops, something went wrong.