Report this

What is the reason for this report?

Django/Nginx/Gunicorn "unknown errors" in nginx logs

Posted on July 17, 2025

Trying to deploy a Django/Nginx/Gunicorn project, I cannot resolve a 502 Bad Gateway issue. Looking at nginx logs, I see “104: unknown error” and “111: unknown error”-- which seems kind of uninformative. How do I debug this further?

p.s. the most recent error recorded goes like this: "*28 connect() to unix:/home/username/gunicorn.socket failed (2: No such file or directory) while connecting to upstream, client: IP_ADDRESS, server: _, request: “GET / HTTP/1.1”, upstream: “http://unix:/home/username/gunicorn.socket:/”, host: “MY_DROPLET_IP_ADDRESS:80” "

I can post some details of my gunicorn.service and nginx configuration if this isn’t enough… been fighting with this for hours, coming from Apache2 and WSGI it’s a lot more moving pieces.



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!

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.

Hi there,

Sounds like your Gunicorn socket isn’t being created or Nginx isn’t pointing at it correctly.

This DigitalOcean guide on setting up Django with Postgres, Nginx & Gunicorn walks through creating the systemd socket, service files, and Nginx proxy config, double check those steps:

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

Look into your Gunicorn systemd logs (e.g. journalctl -u gunicorn.socket) and your Nginx error logs, you’ll usually find clues like missing socket files, permission issues, or path problems.

If everything matches the tutorial but it’s still failing, post your gunicorn.socket, gunicorn.service, and Nginx site config. That way the community could advise you better.

- Bobby

Heya,

connect() to unix:/home/username/gunicorn.socket failed (2: No such file or directory)

This means Nginx is trying to connect to a Unix socket at /home/username/gunicorn.socket, but that socket file doesn’t exist, which almost always means Gunicorn is either not running, crashed, or is configured to place the socket somewhere else.

Check if your gunicorn is working at all:

sudo systemctl status gunicorn

Look for signs of failure, such as exit codes or tracebacks.

You can also check the logs for more info

journalctl -u gunicorn.service --since "10 minutes ago"

Ensure that your gunicorn.service file has the correct --bind path:

ExecStart=/path/to/venv/bin/gunicorn \
    --workers 3 \
    --bind unix:/home/username/gunicorn.socket \
    myproject.wsgi:application

And that /home/username/ is writable by the user running Gunicorn, and the directory exists.

If it doesn’t, either:

  • Create the directory (and give it proper permissions), or

  • Change the socket location to something like /run/gunicorn.sock or /tmp/gunicorn.sock

Thanks, everyone–I actually had been following that tutorial, but there were some conflicts between the instructions given there and the default django_project setup that was pre-installed in the Droplet. It took a while to sort everything out but my project is up and running now! For posterity, here are the things I had to change:

  • The instructions in the tutorial were followed to the T. The droplet’s gunicorn.service file had a slightly different syntax (no "" lines) which was breaking some things.
  • The django_project settings file had the ALLOWED_HOSTS set dynamically via a custom function using the ‘netifaces’ module. I had to change it to my registered domain name, and for some reason it didn’t work properly until I changed it to “.blahblah.net” instead of “subdomain.blahblah.net”.

The developer cloud

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

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.