uWSGI根据环境变量设置配置

时间:2017-11-03 08:12:21

标签: uwsgi

请帮我理解uWSGI配置逻辑。 我有一个环境变量ENVIRONMENT。我们可以说它的值可以是devprod。我想根据ENVIRONMENT

的值设置配置选项
# always executes print statement, doesn't matter what ENVIRONMENT is set to
if-env= ENVIRONMENT
if-opt: %(_)=dev
print = RUNNING %(_)
endif:
endif =

# always executes print statement, doesn't matter what ENVIRONMENT is set to
running = ENVIRONMENT
if-opt: running=dev
print = RUNNING %(_)
endif:

我认为如果ENVIRONMENT设置为prod,则print块中的任何分配或if-opt语句都不会执行。但事实并非如此。

1 个答案:

答案 0 :(得分:3)

这应该有效:

[uwsgi]
if-env = ENVIRONMENT
env = %(_)
endif =
if-not-env = ENVIRONMENT
env = none
endif =
print = RUNNING %(env)
if-opt = env=dev
print = running dev yay
endif =

您在INI配置中使用YAML语法。我还必须从if-opt中取出if-env,因为它抱怨递归。可能有一种方法可以缩短它,但这很有效。