Report this

What is the reason for this report?

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

Posted on May 24, 2021

I am trying to upload my django project to digitalocean droplet. Followed this article https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-20-04 to upload it.

After completing all the steps I am getting 502 bad gateway. Also the server is not running on SSL rather it is running on http//.

I followed every steps the article provided. Somehow there is an error called “connect() to unix:/run/gunicorn.sock failed (111: Connection refused) while connecting to upstream”

/etc/systemd/system/gunicorn.socket -----

[Unit]
    Description=gunicorn socket
    
    [Socket]
    ListenStream=/run/gunicorn.sock
    
    [Install]
    WantedBy=sockets.target

/etc/systemd/system/gunicorn.service ----

[Unit]
    Description=gunicorn daemon
    Requires=gunicorn.socket
    After=network.target
    
    [Service]
    User=sammy
    Group=www-data
    WorkingDirectory=/home/sammy/myprojectdir
    ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
              --access-logfile - \
              --workers 3 \
              --bind unix:/run/gunicorn.sock \
              myproject.wsgi:application
    
    [Install]
    WantedBy=multi-user.target

/etc/nginx/sites-available/myproject -----

server {
        listen 80;
        server_name server_domain_or_IP;
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
            root /home/sammy/myprojectdir;
        }
    
        location / {
            include proxy_params;
            proxy_pass http://unix:/run/gunicorn.sock;
        }
    }

I ran this commands but getting no error

sudo nginx -t && sudo systemctl restart nginx

So I need help on this.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.