Skip to content
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

[backport -> release/3.4.x] fix(template): fix failure of starting if proxy_access_log is off #12078

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kong/cmd/utils/prefix_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ local function compile_conf(kong_config, conf_template)
-- computed config properties for templating
local compile_env = {
_escape = ">",
proxy_access_log_enabled = kong_config.proxy_access_log ~= "off",
pairs = pairs,
ipairs = ipairs,
tostring = tostring,
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 @@ -81,7 +81,12 @@ server {
# https://github.com/Kong/lua-kong-nginx-module#lua_kong_error_log_request_id
lua_kong_error_log_request_id $kong_request_id;

> if proxy_access_log_enabled then
access_log ${{PROXY_ACCESS_LOG}} kong_log_format;
> else
access_log off;
> end

error_log ${{PROXY_ERROR_LOG}} ${{LOG_LEVEL}};

> if proxy_ssl_enabled then
Expand Down
10 changes: 10 additions & 0 deletions spec/01-unit/04-prefix_handler_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,16 @@ describe("NGINX conf compiler", function()
local nginx_conf = prefix_handler.compile_kong_stream_conf(conf)
assert.matches("access_log%slogs/access.log%sbasic;", nginx_conf)

local conf = assert(conf_loader(nil, {
proxy_access_log = "off",
stream_listen = "0.0.0.0:9100",
nginx_stream_tcp_nodelay = "on",
}))
local nginx_conf = prefix_handler.compile_kong_conf(conf)
assert.matches("access_log%soff;", nginx_conf)
local nginx_conf = prefix_handler.compile_kong_stream_conf(conf)
assert.matches("access_log%slogs/access.log%sbasic;", nginx_conf)

local conf = assert(conf_loader(nil, {
proxy_stream_access_log = "/dev/stdout custom",
stream_listen = "0.0.0.0:9100",
Expand Down
Loading