Question

connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream, client:

I’m getting the “502 Bad Gateway” error…when I run the command sudo netstat -plant | grep '80\|443' I get the following

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      22248/nginx: master 
tcp6       0      0 :::80                   :::*                    LISTEN      22248/nginx: master 

**My ngnix configurations are **

server {
    listen 80;
    server_name MY_IP_ADDRESS;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/antonnifo/pyapps/FML;
    }
    
    location /media/ {
        root /home/antonnifo/pyapps/FML;    
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }
}

I have no idea what’s up but I have a feeling it has to do with the missing 443…Any help will be highly appreciated

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Accepted Answer

Hi there @amwangi,

The 502 error indicates that the backend service is not up and running.

You need to make sure that the gunicorn service is up and running, if for any reason it is failing to start I would recommend checking the logs. You can check if the service is running and restart it if not with the following commands:

# Check the status
systemctl status gunicorn
# Restart:
systemctl restart gunicorn

For more information on how to troubleshoot Gunicorn problems with Nginx, I would recommend the Troubleshooting Nginx and Gunicorn step from this tutorial here:

https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04

The missing 443 port indicates that there is no SSL certificate installed on the server.

Regards, Bobby