nginx conf 外推的环境变量
Environment variable for nginx conf extrapolation
我正在使用 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" }}/ 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 ^(.*)$ // last;
# ^- I should have app_dev.php between the `//`
}
# ...
- 我是不是做错了什么?
- 我该如何调试它?
与what is documented不同,confd
(0.11.0) getenv
函数似乎不期望环境变量作为路径/app/entry/point
。
环境变量确实保持原样:APP_ENTRY_POINT
所以模板应该简单地说:
$ cat /etc/confd/templates/my_app.tmpl
# ...
location @rewriteapp {
rewrite ^(.*)$ /{{ getenv "APP_ENTRY_POINT" }}/ last;
}
# ...
有 -debug
和 -verbose
选项可以检查正在发生的事情
我正在使用 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" }}/ 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 ^(.*)$ // last;
# ^- I should have app_dev.php between the `//`
}
# ...
- 我是不是做错了什么?
- 我该如何调试它?
与what is documented不同,confd
(0.11.0) getenv
函数似乎不期望环境变量作为路径/app/entry/point
。
环境变量确实保持原样:APP_ENTRY_POINT
所以模板应该简单地说:
$ cat /etc/confd/templates/my_app.tmpl
# ...
location @rewriteapp {
rewrite ^(.*)$ /{{ getenv "APP_ENTRY_POINT" }}/ last;
}
# ...
有 -debug
和 -verbose
选项可以检查正在发生的事情