uWSGI 根据环境变量设置配置 [英] uWSGI set configuration depending on environment variable
问题描述
请帮我理解uWSGI的配置逻辑.我有一个环境变量 ENVIRONMENT
.假设它的值可以是 dev
或 prod
.我想根据 ENVIRONMENT
Please help me understand uWSGI configuration logic.
I have an environment variable ENVIRONMENT
. Let's say its values can either be dev
or prod
. I want to set configuration options based on value of 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
在 if-opt
中没有任何赋值或 print
语句> 块将执行.但事实并非如此.
I would assume if ENVIRONMENT
is set to prod
none of the assignments or print
statements inside if-opt
block would execute. But this not the case.
推荐答案
这应该有效:
[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
中去掉,因为它抱怨递归.可能有办法让它更短,但这是有效的.
You were using YAML syntax in INI configuration. I also had to take if-opt
out of if-env
because it was complaining about recursion. There might be a way to make it shorter, but this works.
这篇关于uWSGI 根据环境变量设置配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!