connect Nginx to Gunicorn

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

First, please don’t try to obfuscate directory or file names. It’s too easy to create inconsistencies, leading to confusion.

What is creating the gunicorn.sock file? What permissions are assigned to it?

I thought it would be better from a security perspective.

Gunicorn is what creates the file, as far as I know.

Thanks KenWhitesell.

I double-checked the user’s permissions and granted it the proper permissions to access the folders in the gunicorn.sock path.