I get a 502 Gateway error on the webpage.
So I checked the Gunicorn log file at /var/log/upstart/gunicorn.log and I got an import error.
ImportError: No module named django_project.wsgi
Which is odd that it is using the django_project folder as I have configured everything to a folder named ProjectStar in the /home/django folder.
/etc/nginx/sites-enabled/django
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/ProjectStar/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/ProjectStar/static;
}
}
And the /etc/init/gunicorn.conf file
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
setuid django
setgid django
chdir /home/django
exec gunicorn \
--name=ProjectStar \
--pythonpath=ProjectStar \
--bind=0.0.0.0:9000 \
--config /etc/gunicorn.d/gunicorn.py \
django_project.wsgi:application
I have tried restarting and stopping nginx and gunicorn but the error in the log does not change. Please help.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I found the solution to my problem: edit /etc/init/gunicorn.conf and change django_project.wsgi:application to my_app.wsgi:application (to match what’s in settings.py).
Maybe this is what was wrong with your setup as well.
Check the settings.py file for the project. Did you start by copying the one from the default project? It likely still contains the line:
WSGI_APPLICATION = 'django_project.wsgi.application'
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.