nginxconfd

Environment variable for nginx conf extrapolation


I'm using confd to render my configuration files depending on my environments

$ ls -R /etc/confd
/etc/confd/:
conf.d  templates

/etc/confd/conf.d:
my_app.toml

/etc/confd/templates:
my_app.tmpl

My configurations:

$ cat /etc/confd/conf.d/my_app.toml
[template]
src = "my_app.tmpl"
dest = "/etc/nginx/sites-enabled/my_app.conf"
$ cat /etc/confd/templates/my_app.tmpl
# ...
    location @rewriteapp {
        rewrite ^(.*)$ /{{ getenv "/app/entry/point" }}/$1 last;
    }
# ...

confd runs well

$ export APP_ENTRY_POINT="app_dev.php"
$ confd -onetime -backend env
2016-04-15T13:54:29Z 1c682a040707 /usr/local/bin/confd[44]: INFO Backend set to env
2016-04-15T13:54:29Z 1c682a040707 /usr/local/bin/confd[44]: INFO Starting confd
2016-04-15T13:54:29Z 1c682a040707 /usr/local/bin/confd[44]: INFO Backend nodes set to
2016-04-15T13:54:29Z 1c682a040707 /usr/local/bin/confd[44]: INFO Target config /etc/nginx/sites-enabled/my_app.conf out of sync
2016-04-15T13:54:29Z 1c682a040707 /usr/local/bin/confd[44]: INFO Target config /etc/nginx/sites-enabled/my_app.conf has been updated

But the generated file does not get the variable resolved

$ cat /etc/nginx/sites-enabled/my_app.conf
# ...
    location @rewriteapp {
        rewrite ^(.*)$ //$1 last;
#                       ^- I should have app_dev.php between the `//`
    }
# ...

Solution

  • Unlike what is documented, confd (0.11.0) getenv function does not seem to expect environment variables as path /app/entry/point.

    The environment variable is indeed kept as is: APP_ENTRY_POINT

    So the template should simply say:

    $ cat /etc/confd/templates/my_app.tmpl
    # ...
        location @rewriteapp {
            rewrite ^(.*)$ /{{ getenv "APP_ENTRY_POINT" }}/$1 last;
        }
    # ...
    

    There are -debug & -verbose options to check what is going on