davegri
By:
davegri

Django + nginx + gunicorn 502 bad gateway

October 7, 2015 4k views
Deployment Nginx Django Getting Started Python Python Frameworks Ubuntu

Trying to set this all up, followed a tutorial, still doesn't work.

gunicorn.conf

description "Gunicorn application server handling stocksearch"

start on runlevel [2345]
stop on runlevel [!2345]


setuid david
setgid www-data
chdir /home/david/stocksearch/stocksearch

exec /home/david/.virtualenvs/stocksearch/bin/gunicorn --workers 3 --bind unix:/home/david/stocksearch/stocksearch/stocksearch.sock stocksearch.wsgi:application

Nginx config:

server {
    listen 80;
    server_name 128.199.36.78;


    location /static/ {
        root /home/david/stocksearch/stocksearch;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/david/stocksearch/stocksearch/stocksearch.sock;
    }
}

Django:

# -*- coding: utf-8 -*-
from .base import *

DEBUG = False

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'stocksearch_db',
        'USER': 'david',
        'PASSWORD': 'david',
        'HOST': '',
        'PORT': '',
    }
}


STATIC_ROOT = os.path.dirname(BASE_DIR)
STATIC_URL = '/static/'

nginx logs:

2015/10/06 20:56:15 [error] 30688#0: *37 connect() to
unix:/home/david/stocksearch/stocksearch/stocksearch.sock failed (111:
Connection refused) while connecting to upstream, client:
79.176.114.181, server: 128.199.36.78, request: "GET / HTTP/1.1", upstream:
"http://unix:/home/david/stocksearch/stocksearch/stocksearch.sock:/",
host: "128.199.36.78" 2015/10/06 20:56:15 [error] 30688#0: *37
connect() to unix:/home/david/stocksearch/stocksearch/stocksearch.sock
failed (111: Connection refused) while connecting to upstream, client:
79.176.114.181, server: 128.199.36.78, request: "GET / HTTP/1.1", upstream:
"http://unix:/home/david/stocksearch/stocksearch/stocksearch.sock:/",
host: "128.199.36.78"

gunicorn logs:

self.halt(reason=inst.reason, exitstatus=inst.exitstatus) File "/home/david/.virtualenvs/stocksearch/lib/python3.4/site-packages/gunicorn/arbiter.py",
line 297, in halt
self.stop() File "/home/david/.virtualenvs/stocksearch/lib/python3.4/site-packages/gunicorn/arbiter.py",
line 342, in stop
time.sleep(0.1) File "/home/david/.virtualenvs/stocksearch/lib/python3.4/site-packages/gunicorn/arbiter.py",
line 214, in handlechld
self.reap
workers() File "/home/david/.virtualenvs/stocksearch/lib/python3.4/site-packages/gunicorn/arbiter.py",
line 459, in reapworkers
raise HaltServer(reason, self.WORKER
BOOT_ERROR) gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

1 comment
1 Answer
Have another answer? Share your knowledge.