✓ Solved

Got 502 Bad Gateway deploying django with gunicorn and nginx

I'm deploying a django app with gunicorn and nginx. I have followed this. Everything is working until the end when I try to open the IP address on my browser and I get "Got 502 Bad Gateway".

The nginx error log I receive is as follows:

2022/11/20 11:24:33 [crit] 4949#4949: *5 connect() to
unix:/home/rypptc/polman_project/polman_project.sock failed (13:
Permission denied) while connecting to upstream, client: 181.43.95.34,
server: 139.144.19.155, request: "GET / HTTP/1.1", upstream:
"http://unix:/home/rypptc/polman_project/polman_project.sock:/", host:
"139.144.19.155"

ufw status on server:

To Action From
-- ------ ---- 22/tcp ALLOW Anywhere Nginx Full
ALLOW Anywhere 22/tcp (v6)
ALLOW Anywhere (v6) Nginx Full (v6)
ALLOW Anywhere (v6)

/etc/systemd/system/gunicorn.service

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

[Service] User=rypptc Group=www-data
WorkingDirectory=/home/rypptc/polman_project
ExecStart=/home/rypptc/polman_project/.venv/bin/gunicorn
--access-logfile - --workers 3 --bind unix:/home/username/polman_project/polman_project.sock
polman_project.wsgi:application

[Install] WantedBy=multi-user.target

server {
listen 80;
server_name 139.144.19.155;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/rypptc/polman_project;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/rypptc/polman_project/polman_project.sock;
}
}

I would appreciate any advice.

2 Replies

✓ Best Answer

2022/11/20 11:24:33 [crit] 4949#4949: *5 connect() to
unix:/home/rypptc/polman_project/polman_project.sock failed (13:
Permission denied) while connecting to upstream, client: 181.43.95.3

This is a permission error on connecting to a Unix-domain socket. Communication on Unix-domain sockets cannot cross system boundaries so your firewall doesn't affect them.

Anyway, some component of socket path /home/rypptc/polman_project/polman_project.sock has incorrect permission/ownership.

-- sw

Thank you very much @stevewi, I changed the user permissions and now it is showing up.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct