Reputation: 130
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?
Upvotes: 3
Views: 4143
Reputation: 7855
I had a similar issue defining environment configurations for a django Mezzanine CMS deployment.
As the DEPLOY_VERSION seems to target the underlying application and not the uWSGI service, I think the correct place to put it to be the uWSGI configuration file instead of the Nginx one.
Try changing the .xml file to:
<uwsgi>
<master/>
<vhost/>
<memory-report/>
<env>DEPLOY_VERSION=Development</env> <!-- this -->
<no-site/>
</uwsgi>
Upvotes: 3
Reputation: 1035
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)
Upvotes: 3