Nginx log format error unexpected "k"

On setting the KONG_NGINX_HTTP_LOG_FORMAT env variable it throws the below error

 Error: could not prepare Kong prefix at /usr/local/kong: nginx configuration is invalid (exit code 1):
kong_1  | nginx: [emerg] unexpected "k" in /usr/local/kong/nginx-kong.conf:45
kong_1  | nginx: configuration file /usr/local/kong/nginx.conf test failed

Trying to set a json format log format

KONG_NGINX_HTTP_LOG_FORMAT=compression escape=json '{\"time_local\":\"$time_local\", \"remote_addr\":\"$remote_addr\",\"remote_user\":\"$remote_user\",\"request\":\"$request\",\"status\":$status,\"body_bytes_sent\":$body_bytes_sent,\"request_time\":$request_time,\"http_referrer\":\"$http_referer\", \"http_user_agent\":\"$http_user_agent\",\"http_x_forwarded_for\":\"$http_x_forwarded_for\",\"host\":\"$host\"}

Kong Version: 2.5

Since you’re using one of the KONG_NGINX environment variables I would advise use the kong prepare CLI command to see what your nginx.conf looks like at that line. It’s possible that you’re escaping the string incorrectly or, due to some implicit variable substitution, you need to tweak your input slightly.

© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ