问题
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:
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.
回答1:
This should work:
[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 =
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.
来源:https://stackoverflow.com/questions/47091122/uwsgi-set-configuration-depending-on-environment-variable