Nginx – 502 bad gateway: nginx & gunicorn

gunicornnginx

I'm getting a 502 error, here's the nginx log:

2015/09/04 15:25:31 [error] 1563#0: *1 connect() to unix:/home/90158/test/test.sock failed (111: Connection refused) while connecting to upstream, client: 142.29.143.200, server: hackerspace.sd72.bc.ca, request: "GET / HTTP/1.1", upstream: "http://unix:/home/90158/test/test.sock:/", host: "hackerspace.sd72.bc.ca"

I'm new to nginx/gunicorn and need to know what I can do next to troubleshoot this problem.

/home/90158/test/test.sock exists.

here's my nginx conf file:

server {
    listen 80;
    server_name hackerspace.sd72.bc.ca;
    access_log /var/log/nginx/test.access.log;
    error_log /var/log/nginx/test.error.log;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/90158/test/src;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/90158/test/test.sock;
    }
}

and here's my gunicorn conf file:

description "Gunicorn application server handling test_project"

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

respawn
setuid 90158
setgid www-data
chdir /home/90158/test

exec bin/gunicorn --workers 3 --bind unix:/home/90158/test/test.sock src/test_project.wsgi:application

What am I doing wrong?

Best Answer

Next steps to troubleshoot:

  • Is the file actually a socket?
  • Is your gunicorn server actually listening to the socket?

Per unix(7), ECONNREFUSED can be returned by connect(2) if the socket is not a "listening socket" -- a clunky way of saying, "something is listening". "This error can also occur if the target filename is not a socket."