uWSGI 根据环境变量设置配置 [英] uWSGI set configuration depending on environment variable

查看:58
本文介绍了uWSGI 根据环境变量设置配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我理解uWSGI的配置逻辑.我有一个环境变量 ENVIRONMENT.假设它的值可以是 devprod.我想根据 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 设置为 prodif-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-optif-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆