I have a Django webapp running on an Ubuntu server using nginx and gunicorn. I'm trying to get my settings.py
set up properly in regards to using environment variables to hide secret information such as the SECRET_KEY
as well as API keys.
I've tried putting export SECRET_KEY='secret_key'
in .bashrc
as well as .profile
, and using SECRET_KEY=os.environ['SECRET_KEY']
in my settings.py
file, but this throws a 502 bad gateway error with nginx and its version at the bottom, upon restarting gunicorn. I'm not sure what else to try, as I'm pretty new to setting up servers.
I believe this is the init file for my gunicorn service:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=myuser
Group=www-data
WorkingDirectory=/home/myuser/myproject/mysite
ExecStart=/home/myuser/myproject/mysite/myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/myuser/myproject/mysite/mysite.sock mysite.wsgi:application
[Install]
WantedBy=multi-user.target
I found this error in the nginx error log when trying to request the site, where it gives the 502 bad gateway:
*20 connect() to unix:/home/myuser/myproject/mysite/mysite.sock failed (2: No such file or directory)
service
to start gunicorn, that means you are running it under upstart. You should post the init script you are using.