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

Posted May 28, 2021 510 views
NginxDjangoUbuntu 20.04

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    *               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

edited by MattIPv4

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.

Submit an Answer
1 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:

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


by Justin Ellingwood
Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server...