i installed django on ubuntu using the one-click install, and am now trying to import an existing django project.
using python manage.py runserver 0:9000
i have no problem, if i go to my site address, i see my project. but if i stop the django ‘runserver’ and run service gunicorn restart
, then visit my page, i get a ‘502 Bad Gateway’ error.
i did upgrade my droplet’s django to 1.7 using pip install --upgrade
. everything else seems to be working fine
on a related point… i am new to servers, and still unclear of what nginx, gunicorn, and wsgi are, and what the flow of information is between them, so if someone could briefly explain that, or point me to a good tutorial, much appreciated.
my nginx error log says the following:
2015/02/25 16:53:16 [error] 1052#0: *191 connect() failed (111: Connection refused) while connecting to upstream, client: 76.98.74.102, server: _, request: "GET /home/ HTTP/1.1", upstream: "http://127.0.0.1:9000/home/", host: "104.236.29.98"
my django project is in /home/django/myproject/
/etc/init/gunicorn.conf:
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
respawn
setuid django
setgid django
chdir /home/django
exec gunicorn \
--name=open_elections \
--pythonpath=open_elections \
--bind=0.0.0.0:9000 \
--config /etc/gunicorn.d/gunicorn.py \
open_elections.wsgi:application
/etc/nginx/sites-available/myproject:
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;
server_name localhost;
keepalive_timeout 5;
location /media {
alias /home/django/myproject/media;
}
location /static {
alias /home/django/myproject/mysite/static;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
mproject/mysite/wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
I have changed the following line
WorkingDirectory=/home/mushegh/artkaren
to
WorkingDirectory=/home/mushegh/artkaren/artkaren
et voila, it works!!!
I had that issue as well. But my problem was that I did not have gevent installed. The gunicorn log showed an error that said: gevent is required to run this worker
or something similar. So,
installing gevent: pip install gevent
, fixed it for me.
This comment has been deleted
Click below to sign up and get $100 of credit to try our products over 60 days!
@pav, yes i ultimately resolved it, but it’s been so long now, i don’t remember how. and i stopped working on the site soon thereafter, so my droplet is now gone. all i remember was uninstalling and re-installing stuff in various combinations of order and settings. but in the end, it may have been something stupid like a port number not matching. i don’t remember. sorry i cant be more help
Did anyone solve this problem?
I’m having the same problem, don’t actually see any errors, just can’t get my django project to show up. Really strange since I followed this flask tutorial and it worked fine! So how come flask knows what to do and django is choking?
fwiw, I’m noticing that nginx doesn’t seem to be finding my static files…? that’s probably not helping.
I’m having the same problem, and my gunicorn.log contains this repeatedly:
I have checked gunicorn.conf, and it is set to the same user and group as my project files.
Pretty frustrated with this error message, especially after seeing the same question unanswered time and time again. Can anyone FINALLY shed some light into this?
Are there any additional error messages in
/var/log/upstart/gunicorn.log
?