-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(conf) add support to configure nginx directives via kong.conf
Problem ------- Kong ships with an NGINX template which is rendered when Kong starts. There exists no mechanisms to add/update arbitrary NGINX directives to the `nginx.conf` used to run Kong. To change or add any directive, user has to use a custom NGINX template which has to be synced with Kong for a release which introduces changes to Kong's template. Including options in `kong.conf` to configure NGINX directives is not a good solution since the list will be endless. This problem can be seen in #3010, #3323, and #3382. Proposed Solution ----------------- Proposed in #3382: There needs to be a flexible way to specify any NGINX directive via Kong's config file without Kong needing to maintain a list of all NGINX directives. While a clean and ideal solution would be #2355, this commit adopts a simpler approach as described in #3382, and keeps solutions similar to the one proposed in #2675 possible (by way of injecting an `include` directive). NGINX directives can be specified using config variables with prefixes, which helps determine the block in which to place a directive. E.g.: * `nginx_proxy_add_header=Header-Name header-value` will add a `add_header Header-Name header-value;` directive in the proxy `server` block of Kong. * `nginx_http_lua_shared_dict=custom_cache 2k` will add a `lua_shared_dict custom_cache 2k;` directive to `http` block of Kong.
- Loading branch information
1 parent
dcb2536
commit ac0f3f6
Showing
14 changed files
with
287 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
local pl_utils = require "pl.utils" | ||
local log = require "kong.cmd.utils.log" | ||
local fmt = string.format | ||
|
||
|
||
local cmd = [[ printenv ]] | ||
|
||
|
||
local function read_all() | ||
log.debug("reading environment variables: %s", cmd) | ||
|
||
local vars = {} | ||
local success, ret_code, stdout, stderr = pl_utils.executeex(cmd) | ||
if not success or ret_code ~= 0 then | ||
return nil, fmt("could not read environment variables (exit code: %d): %s", | ||
ret_code, stderr) | ||
end | ||
|
||
for line in stdout:gmatch("[^\r\n]+") do | ||
local i = string.find(line, "=") -- match first = | ||
|
||
if i then | ||
local k = string.sub(line, 1, i - 1) | ||
local v = string.sub(line, i + 1) | ||
|
||
if k and v then | ||
vars[k] = v | ||
end | ||
end | ||
end | ||
|
||
return vars | ||
end | ||
|
||
|
||
return { | ||
read_all = read_all, | ||
} |
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
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
Oops, something went wrong.