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

I am trying to upload my django project to digitalocean droplet. Followed this article 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 -----

    Description=gunicorn socket

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

    Description=gunicorn daemon
    ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
              --access-logfile - \
              --workers 3 \
              --bind unix:/run/gunicorn.sock \

/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.

Show comments

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @irfan015

If you haven’t done so already. Restart both the gunicorn service and the nginx service.

Hi @irfan015 did you find a solution to your issue? I’m having the same problem

Hi @irfan015,

Make sure to allow Access to port 80, it’s possible your firewall is in the way!

Additionally, usually, such errors that you receive :

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

This means that there is something wrong with either the configuration for your Nginx Proxy or your Gunicorn app. The one I would bet would be the Gunicorn App. It’s possible somewhere something has not been configured properly. I would suggest seeing if you have configured Gunicorn properly, see if it’s actually listening on any port or if it is at all running.