Adding Custom Nginx Config variables with set

Is it possible at this time to set variables in the server block without having to directly modify nginx-kong.conf? I imagine it would be similar to this:

For example, I’m using a docker-compose.yml file and I can do the following:

  KONG_NGINX_HTTP_LUA_CODE_CACHE: "off" # evaluates to `lua_code_cache: off;` in http block

but I cannot set a variable in the server block like this:


Because this evaluates to set_$session_secret: secret instead of set $session_secret: secret;

I imagine this is probably a shortcoming to the way this functionality works… just wanted to verify it isn’t a user error before I move forward into a method that requires a completely custom nginx-kong.conf file.

I am debugging and currently trying to accomplish this:

@jerney Did you try doing the following?

 KONG_NGINX_PROXY_SET="$session_secret: secret"

This should render the following line inside the proxy server block:
set $session_secret: secret;

1 Like

when I add that line I get

WARNING: The session_secret variable is not set. Defaulting to a blank string.
Creating network "kong_kong-net" with the default driver
Creating kong_kong-db_1 ... done
Creating kong_kong_1    ... done
Attaching to kong_kong-db_1, kong_kong_1
kong-db_1  | LOG:  database system was shut down at 2019-05-09 09:11:17 UTC
kong-db_1  | LOG:  MultiXact member wraparound protections are now enabled
kong-db_1  | LOG:  autovacuum launcher started
kong-db_1  | LOG:  database system is ready to accept connections
kong_1     | Error: could not prepare Kong prefix at /usr/local/kong: nginx configuration is invalid (exit code 1):
kong_1     | nginx: [emerg] invalid variable name ":" in /usr/local/kong/nginx-kong.conf:76
kong_1     | nginx: configuration file /usr/local/kong/nginx.conf test failed

resolved with

KONG_NGINX_PROXY_SET="$$session_secret secret"