我有一个django网站,该网站使用环境变量 DJANGO_MODE 来决定要使用的设置-开发还是暂存.环境变量位于 bashrc 中,并且在使用开发服务器运行应用程序时,一切正常.
I have a django website, that uses an environment variable, DJANGO_MODE to decide which settings to use - development or staging. The environment variable is in the bashrc and when running the app using the development server, everything works fine.
但是当我使用 uWSGI 运行应用程序时,似乎没有注意到环境变量,而是使用默认(开发)设置而不是生产版本.
But when I run the app using uWSGI, it doesn't seem to notice the environment variable and uses the default(development) settings instead of production.
我在Emperor模式下运行 uWSGI ,除了忽略环境变量外,其他一切似乎都运行良好.是的,运行 uWSGI 的用户与 bashrc 设置了 DJANGO_MODE 的用户相同.
I run uWSGI in Emperor mode, and other than the environment variable ignoring, everything seems to be running fine. And yes, the user running uWSGI is the same for which the bashrc has DJANGO_MODE set.
用于运行 uWSGI 的命令是-
exec uwsgi --emperor /etc/uwsgi/vassals --uid web_user --gid --web_user以及 ini的 ini 文件-
[uwsgi] processes = 2 socket = /tmp/uwsgi.sock wsgi-file = /home/web_user/web/project_dir/project/wsgi.py chdir = /home/web_user/web/project_dir virtualenv = /home/web_user/.virtualenvs/production_env logger = syslog chmod-socket = 777 推荐答案由于bash读取bash配置文件,因此无法使用.您必须在皇帝或附庸国中设置var(第二种方法是更好的方法).只需添加
It cannot work as bash config files are read by the bash. You have to set var in the emperor or in the vassal (the second one is a better approach). Just add
env=DJANGO_MODE=foobar到您的配置(请勿使用空格).
to your config (do not use whitespace).
更多推荐
通过uWSGI运行时Django忽略环境变量
发布评论