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?