-
Notifications
You must be signed in to change notification settings - Fork 8.4k
NGINX: Remove inline Lua from template. #11806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
27cbb6d
f793b46
2614b48
e327abd
9b923c8
3b12461
d049b2e
aa5c3ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,2 @@ | ||||||
local balancer = require("balancer") | ||||||
balancer.balance() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have the newline at EOF added in snippets? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry I am not following. What would be the goal of adding a new line here? |
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local certificate = require("certificate") | ||
certificate.call() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local configuration = require("configuration") | ||
configuration.call() |
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() |
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() |
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) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local monitor = require("monitor") | ||
monitor.call() |
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") | ||
|
||
rikatz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
balancer.log() | ||
|
||
if enablemetrics then | ||
monitor.call() | ||
end |
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)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local lua_ingress = require("lua_ingress") | ||
lua_ingress.header() |
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() |
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) |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never tried. but then wouldn't it be better to change all of the ifs for this approach on a follow up PR?