Reputation: 1051
I have a WSGI handler configured under Apache and I'm defining some environmental variables in the Apache virtual host configuration.
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.
uwsgi --http :9090 --ini uwsgi.ini --wsgi-file 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?
I have tried setting environmental variables in the uwsgi.ini file:
[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'
Upvotes: 6
Views: 15049
Reputation: 81
[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
Upvotes: 8
Reputation: 146
As pointed in https://stackoverflow.com/a/18490958/3383797 do not use whitespaces:
[uwsgi]
env=MY_VAR_NAME=foobar
Upvotes: 3
Reputation: 1051
I discovered how to do this using addvar
in the wsgi.ini
:
[uwsgi]
route-run = addvar:APP_CONFIG="/var/lib/myapp/app.config"
Upvotes: 1
Reputation: 309
I think you just need to specify you .ini file
uwsgi --ini uwsgi.ini --http = :9090 --wsgi-file wsgi.py
Upvotes: 1