I am trying to configure nginx+uWSGI to serve my Django application.
When I put environment variables into myapp_uwsgi.ini
:
uid = username
gid = username
env = DJANGO_SITE_KEY="..."
it works as expected.
However, my app has some management commands which should also have access to the environment variables I have defined.
If I put the environment variables to /home/username/.bashrc
:
export DJANGO_SITE_KEY="..."
uWSGI does not load them.
I have tried to put the environment variables into a separate file:
#!/bin/sh
export DJANGO_SITE_KEY="..."
and then call it from both .bashrc
:
. /home/username/environment
and myapp_uwsgi.ini
:
exec-pre-app = . /home/username/environment
In uWSGI logs I see this line:
running ". /home/username/environment" (pre app)...
But my Django app is unable to access the environment variables with os.environ
.
I have also tried putting the export
commands to the preactivate
hook of virtualenvwrapper and use the virtualenv =
setting of uWSGI, but it does not work too (I assume the hooks are only executed when using virtualenvwrapper commands like workon
.