Reputation: 133
When I try to access my site I get a 502 Bad Gateway. So I've look at my logs and I can see that when I run my gunicorn script I get the following error message:
2016/01/14 19:52:22 [error] 25232#0: *1 connect() to unix:/home/dvotedfan/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client: 130.211.0.242, server: dvotedfan.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/dvotedfan/run/gunicorn.sock:/", host: "10.240.0.2"
My nginx config file:
upstream dvotedfan_app_server {
server unix:/home/dvotedfan/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name www.dvotedfan.com dvotedfan.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/dvotedfan/static;
}
location /media/ {
root /home/dvotedfan/media;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://dvotedfan_app_server;
break;
}
}
}
My gunicorn script look like this:
#!/bin/bash
NAME="dvotedfan"
DJANGODIR=/home/dvotedfan/src
SOCKFILE=/home/dvotedfan/run/gunicorn.sock
USER=dvotedfan
NUM_WORKERS=3
MAX_REQUESTS=1
DJANGO_SETTINGS_MODULE=dvotedfan.settings.production
DJANGO_WSGI_MODULE=dvotedfan.wsgi # WSGI module name
echo "Starting $NAME"
cd $DJANGODIR
source /home/dvotedfan/.virtualenvs/dvotedfan/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec /home/dvotedfan/.virtualenvs/dvotedfan/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--user=$USER \
--workers $NUM_WORKERS \
--max-requests $MAX_REQUESTS \
--bind=unix:/home/dvotedfan/run/gunicorn.sock \
--log-level=error \
--log-file=-
If I run ps -ef|grep gunicorn
dvotedf+ 26820 24452 0 21:11 pts/0 00:00:00 nano /home/dvotedfan/scripts/gunicorn.sh
dvotedf+ 26821 24452 0 21:11 pts/0 00:00:00 nano /home/dvotedfan/scripts/gunicorn.sh
dvotedf+ 27003 24452 0 21:16 pts/0 00:00:00 /home/dvotedfan/.virtualenvs/dvotedfan/bin/python /home/dvotedfan/.
virtualenvs/dvotedfan/bin/gunicorn --bind 0.0.0.0:8000 dvotedfan.wsgi:application
dvotedf+ 27008 27003 0 21:16 pts/0 00:00:00 /home/dvotedfan/.virtualenvs/dvotedfan/bin/python /home/dvotedfan/.
virtualenvs/dvotedfan/bin/gunicorn --bind 0.0.0.0:8000 dvotedfan.wsgi:application
dvotedf+ 27199 27123 0 21:20 pts/2 00:00:00 grep --color=auto gunicorn
I'm out of ideas I've look everywhere and couldn't find a solution.
Upvotes: 2
Views: 1430
Reputation: 7719
Your gunicorn is listening to port 8000 so you need to connect to that port. Your nginx conf shoud look like this
http {
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80;
...
location / {
uwsgi_pass django;
include uwsgi_params;
}
}
}
Upvotes: 1