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


Submit an answer


This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
May 28, 2021
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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel