简体   繁体   English

如何将 env 变量传递给 uwsgi?

[英]How do I pass env variables to uwsgi?

I have a WSGI handler configured under Apache and I'm defining some environmental variables in the Apache virtual host configuration.我在 Apache 下配置了一个 WSGI 处理程序,我在 Apache 虚拟主机配置中定义了一些环境变量。

SetEnv APP_CONFIG "/var/lib/myapp/app.config"
SetEnv LOG_CONFIG "/var/lib/myapp/app.logging.yml"

To test the handler in development without having to install and configure Apache I'm using uWSGI with the --http option.为了测试在发展中的处理程序,而不必安装和配置Apache我使用uWSGI--http选项。

uwsgi --http :9090 --ini uwsgi.ini --wsgi-file wsgi.py

wsgi.py wsgi.py

def application(environ, start_response):
    config_file_path = environ['APP_CONFIG']
    start_response('200 OK', [('Content-Type','text/html')])
    return ["Hello World"]

Using the uWSGI http server how can I pass these variables to my application as part of the environ argument?使用 uWSGI http 服务器如何将这些变量作为environ参数的一部分传递给我的应用程序?

I have tried setting environmental variables in the uwsgi.ini file:我尝试在 uwsgi.ini 文件中设置环境变量:

[uwsgi]
env = APP_CONFIG="/var/lib/myapp/app.config"

but I get:但我得到:

File "wsgi.py", line 5, in application
config_file_path = environ['APP_CONFIG']
KeyError: 'APP_CONFIG'

https://appsnomad.com/blog/how-to-put-environment-variable-in-uwsgi-config/29 https://appsnomad.com/blog/how-to-put-environment-variable-in-uwsgi-config/29

[uwsgi]
env             = RAY_REDIS_PASS=ray_pass
env             = RAY_REDIS_PORT=6380
strict          = true
chdir           = /Users/judas/projects/myapp
master-fifo     = /tmp/myapp_fifo0
master-fifo     = /tmp/myapp_fifo1
module          = myapp.wsgi:application
master          = true
vacuum          = true
need-app        = true
processes       = 4
die-on-term     = true
procname-prefix = myapp
harakiri        = 30
socket          = /tmp/myapp_uwsgi.sock
lazy-apps       = true
logger          = file:logfile=/tmp/apps.log,maxsize=2000000000
import          = postfork

我认为你只需要指定你的 .ini 文件

uwsgi --ini uwsgi.ini --http = :9090 --wsgi-file wsgi.py

I discovered how to do this using addvar in the wsgi.ini :我发现如何使用addvar中的wsgi.ini做到这wsgi.ini

[uwsgi]
route-run = addvar:APP_CONFIG="/var/lib/myapp/app.config"

As pointed in https://stackoverflow.com/a/18490958/3383797 do not use whitespaces :正如https://stackoverflow.com/a/18490958/3383797所指出的,不要使用空格

[uwsgi]
env=MY_VAR_NAME=foobar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM