1
I'm getting 502 Bad Gateway error when accessing my Django site through Nginx. Gunicorn seems to be running. How do I fix this?
Loading...
Q&A · Answered
I'm getting 502 Bad Gateway error when accessing my Django site through Nginx. Gunicorn seems to be running. How do I fix this?
Accepted answer
502 errors usually indicate Nginx cannot communicate with Gunicorn. Here's how to fix:
sudo systemctl status gunicorn
# Check if socket exists
ls -la /run/gunicorn.sock
# In gunicorn.service
[Service]
User=www-data
Group=www-data
# Restart gunicorn
sudo systemctl restart gunicorn
upstream django {
server unix:/run/gunicorn.sock fail_timeout=0;
}
server {
location / {
proxy_pass http://django;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.