diff --git a/kong/cmd/utils/prefix_handler.lua b/kong/cmd/utils/prefix_handler.lua index 87f675e43f8b..ea661fbf4ca0 100644 --- a/kong/cmd/utils/prefix_handler.lua +++ b/kong/cmd/utils/prefix_handler.lua @@ -239,6 +239,7 @@ local function compile_conf(kong_config, conf_template, template_env_inject) -- 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, diff --git a/kong/templates/nginx_kong.lua b/kong/templates/nginx_kong.lua index 283d6c6f0c93..2da98f9213d6 100644 --- a/kong/templates/nginx_kong.lua +++ b/kong/templates/nginx_kong.lua @@ -85,7 +85,12 @@ server { # https://github.com/Kong/lua-kong-nginx-module#lua_kong_error_log_request_id lua_kong_error_log_request_id $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 diff --git a/spec/01-unit/04-prefix_handler_spec.lua b/spec/01-unit/04-prefix_handler_spec.lua index 50141e70c6c6..27b109fba1a0 100644 --- a/spec/01-unit/04-prefix_handler_spec.lua +++ b/spec/01-unit/04-prefix_handler_spec.lua @@ -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",