Deploying a project using Nginx and Gunicorn on a VPS that runs Ubuntu 24.04 LTS
I have a Bad Gateway 502 error.
Nginx logs show the following message
connect() to unix:/home/projectpath/gunicorn.sock failed (13: Permission denied) while connecting to upstream
Both Nginx and Gunicorn are running and active.
Nginx sites-available
server {
listen 80;
server_name mydomain.com www.mydomain.com;
location / {
proxy_pass http://unix:/home/path to /gunicorn.sock;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static/ {
alias /home/path to my /staticfiles;
}
}
My gunicorn.service file
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=my user
Group=www-data
WorkingDirectory=/home/path to my project
ExecStart=/home/path to/myenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/path to /gunicorn.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
The permissions on my project folder path
drwxr-xr-x root root /
drwxr-xr-x root root home
drwxr-x--- user user folder in the path
drwxr-x--- user www-data myproject