I am building a website using Django, Nginx and Gunicorn. Everything worked perfectly fine for months, until today after I restarted nginx service, my website gives my 502 bad gateway.

root@xxx:/# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Here is the error log (my website is in PRODUCTION):

root@xxx:/# cat /var/log/nginx/error.log

2019/06/05 11:53:44 [error] 1577#1577: *3 connect() to unix:/home/xxx/xxx/xxx.sock failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.net, request: "GET / HTTP/1.1", upstream: "http://unix:/xxx/xxx/xxx/xxx.sock:/", host: "xxx.net"

Here is the conf:

root@vps675614:/# cat /etc/nginx/sites-enabled/xxx 
server {
    server_name xxx.net;

    location = /favicon.ico { access_log off; log_not_found off; }

    location / {
        include proxy_params;
        proxy_pass http://unix:/xxx/xxx/xxx/xxx.sock;

    location /static/ {
       alias /xxx/xxx/xxx/static/;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/xxx.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/xxx.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

server {
    if ($host = xxx.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name xxx.net;
    return 404; # managed by Certbot


Server: Ubuntu 18.04 LTS

  • Your configuration looks odd. It is not usual that one uses proxy_pass to a unix domain socket. How exactly is your application server configured? Commented Jun 5, 2019 at 20:05
  • I am a newbie so I can't really answer you. What do you want to know exactly ?
    – qux
    Commented Jun 7, 2019 at 19:29

1 Answer 1


Based on http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass, the path for the unix socket has to be fully enclosed by two colons, so your proxy_pass line should look like:

proxy_pass http://unix:/xxx/xxx/xxx/xxx.sock:/;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .