Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

607
Views
Django + Nginx + Gunicorn setup with error: (104: Connection reset by peer) while reading response header from upstream

I have a server set up with Ubuntu 20.04, Nginx and running a Django app with Gunicorn. My gunicorn.socket file is like so:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

And My gunicorn.service file is so:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/root/backend
ExecStart=/root/.local/share/virtualenvs/backend-Lu9kB6KY/bin/gunicorn \
        --access-logfile /var/log/nginx/backend.log \
        --workers 3 \
        --bind unix:/run/gunicorn.sock \
        backend.wsgi:application

[Install]
WantedBy=multi-user.target

And in a file at /etc/nginx/sites-available/backend, I have:

server {
        listen 80;
        listen [::]:80;

        server_name domain.com;

        location = /favicon.ico { access_log off; log_not_found off; }
        location /static/ {
                root /root/backend/;
        }

        location / {
                include proxy_params;
                proxy_pass http://unix:/run/gunicorn.sock;
        }
}

When I visit the homepage, I see a 502 Bad Gateway error, and the logs at /var/log/nginx/error.log shows: [error] 15866#15866: *86 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 82.102.24.9, server: domain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/run/gunicorn.sock:/", host: "domain.com"

What have I done wrong? What to do?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!