So, I’ve been struggling for the past week to deploy my Django project on my VPS server (domains.co.za). After all this time, I managed to figure out a few things on my own. My server runs on AlmaLinux 9, and I’m connecting via the IP address 41.76.110.165. Here’s what I’ve done so far:
Gunicorn Configuration (/etc/systemd/system/gunicorn.service)
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=marco
Group=www-data
WorkingDirectory=/home/marco/domestic_voicelogging
ExecStart=/home/marco/domestic_voicelogging/venv/bin/gunicorn
--access-logfile -
--workers 3
--bind unix:/run/gunicorn.sock
domestic_voicelogging.wsgi:application
[Install]
WantedBy=multi-user.target
Gunicorn Socket (/etc/systemd/system/gunicorn.socket)
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
SocketUser=marco
SocketGroup=www-data
SocketMode=0660
[Install]
WantedBy=sockets.target
Nginx Configuration (/etc/nginx/sites-available/myproject)
server {
listen 80;
server_name 41.76.110.165;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/marco/domestic_voicelogging;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
I’m encountering this error:
2024/07/09 10:11:40 [crit] 21042#21042: *8 connect() to unix:/opt/domestic_voicelogging.sock failed (2: No such file or directory) while connecting to upstream, client: 41.13.200.12, server: mydjangoserver.co.za, request: "GET / HTTP/1.1", upstream: "http://unix:/opt/domestic_voicelogging.sock:/", host: "41.76.110.165"
Current Socket Status
(venv) [marco@mydjangoserver domestic_voicelogging]$ ls -l /run/gunicorn.sock
srw-rw-rw-. 1 marco www-data 0 Jul 9 09:37 /run/gunicorn.sock
(venv) [marco@mydjangoserver domestic_voicelogging]$
I’m puzzled why the directory path in the error message shows /opt/domestic_voicelogging.sock instead of /run/gunicorn.sock. I’ve checked everything seems correct, yet I’m still unable to access my site via IP, receiving a “502 Bad Gateway” error.
Could someone please assist with troubleshooting this issue?
Marco Fourie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.