我使用confd
根据我的环境呈现配置文件
$ ls -R /etc/confd
/etc/confd/:
conf.d templates
/etc/confd/conf.d:
my_app.toml
/etc/confd/templates:
my_app.tmpl
我的配置:
$ 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
运行良好
$ 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
但生成的文件无法解析变量
$ cat /etc/nginx/sites-enabled/my_app.conf
# ...
location @rewriteapp {
rewrite ^(.*)$ //$1 last;
# ^- I should have app_dev.php between the `//`
}
# ...
答案 0 :(得分:1)
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