how to get env_vars with nginx UWSGI_SETENV in uwsgi

nginx, python, uwsgi

Solution

Instead of:

uwsgi_param UWSGI_SETENV DEPLOY_VERSION=Development;

You could set it as a per request variable in nginx: `uwsgi_param DEPLOY_VERSION 'Development';`

And then within Flask, access the variable via request.environ: `request.environ['DEPLOY_VERSION']`

(I had a similar problem and was pointed to the above solution on the uwsgi mailing list)

Problem

my nginx conf: ``` location / { include uwsgi_params; uwsgi_param UWSGI_PYHOME /usr; uwsgi_pass unix:/var/run/uwsgi-python/uwsgi/socket; uwsgi_param UWSGI_CHDIR /var/www/my_site; uwsgi_param UWSGI_SCRIPT my_site:app; uwsgi_param SERVER_NAME my_site; uwsgi_param UWSGI_SETENV DEPLOY_VERSION=Development; } ``` my uwsgi para: ``` /usr/local/bin/uwsgi --master --processes 2 --logdate --chmod-socket=666 --uid www --gid www --limit-as 512 --harakiri 60 --max-requests 1000 --no-orphans —-reload-os-env --daemonize /var/log/uwsgi-python/uwsgi.log --pidfile /var/run/uwsgi-python/uwsgi/pid --socket /var/run/uwsgi-python/uwsgi/socket --xmlconfig /etc/uwsgi-python/apps-enabled/uwsgi.xml ``` uwsgi xml: ``` <uwsgi> <master/> <vhost/> <memory-report/> <no-site/> </uwsgi> ``` In my flask app ``` print os.environ.get('DEPLOY_VERSION', 'NONE') #pring NONE ``` How I can get the env_vars? Maybe I can not get the env_vars setting by UWSGI_SETENV in <vhost/><no-site/> mode? btw: How you deploy multi version(Development/Beta/Release) of app in one machine without virtual env?

Original source