Skip to content

Commit

Permalink
feat(conf): inject nginx directives into kong's proxy location block (#…
Browse files Browse the repository at this point in the history
…11623)

`nginx_location_*`: the new prefix allows for the dynamic
injection of Nginx directives into the `/` location block within
Kong's Proxy server block.
  • Loading branch information
vvicaretti authored Nov 13, 2023
1 parent b5c02a6 commit b1b5f94
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: Allow to inject Nginx directives into Kong's proxy location block
type: feature
scope: Configuration
2 changes: 2 additions & 0 deletions kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,8 @@
# - `nginx_http_<directive>`: Injects `<directive>` in Kong's `http {}` block.
# - `nginx_proxy_<directive>`: Injects `<directive>` in Kong's proxy
# `server {}` block.
# - `nginx_location_<directive>`: Injects `<directive>` in Kong's proxy `/`
# location block (nested under Kong's proxy server {} block).
# - `nginx_upstream_<directive>`: Injects `<directive>` in Kong's proxy
# `upstream {}` block.
# - `nginx_admin_<directive>`: Injects `<directive>` in Kong's Admin API
Expand Down
5 changes: 5 additions & 0 deletions kong/conf_loader/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ local DYNAMIC_KEY_NAMESPACES = {
prefix = "nginx_proxy_",
ignore = EMPTY,
},
{
injected_conf_name = "nginx_location_directives",
prefix = "nginx_location_",
ignore = EMPTY,
},
{
injected_conf_name = "nginx_status_directives",
prefix = "nginx_status_",
Expand Down
5 changes: 5 additions & 0 deletions kong/templates/nginx_kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ server {
proxy_buffering on;
proxy_request_buffering on;
# injected nginx_location_* directives
> for _, el in ipairs(nginx_location_directives) do
$(el.name) $(el.value);
> end
proxy_set_header TE $upstream_te;
proxy_set_header Host $upstream_host;
proxy_set_header Upgrade $upstream_upgrade;
Expand Down
8 changes: 8 additions & 0 deletions spec/01-unit/04-prefix_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,14 @@ describe("NGINX conf compiler", function()
assert.matches("large_client_header_buffers%s+16 24k;", nginx_conf)
end)

it("injects nginx_location_* directives", function()
local conf = assert(conf_loader(nil, {
nginx_location_proxy_ignore_headers = "X-Accel-Redirect",
}))
local nginx_conf = prefix_handler.compile_kong_conf(conf)
assert.matches("proxy_ignore_headers%sX%-Accel%-Redirect;", nginx_conf)
end)

it("injects nginx_admin_* directives", function()
local conf = assert(conf_loader(nil, {
nginx_admin_large_client_header_buffers = "4 24k",
Expand Down

1 comment on commit b1b5f94

@khcp-gha-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:b1b5f949e67907876f0a062ac473fe1397b6dbd5
Artifacts available https://github.com/Kong/kong/actions/runs/6852998173

Please sign in to comment.