A reference guide to the Nginx errors you're most likely to encounter in production, with the direct cause and fix for each.
502 Bad Gateway
Nginx couldn't get a valid response from the backend/upstream server it's proxying to.
Common causes and fixes:
- Backend app isn't running — check it directly:
curl http://127.0.0.1:3000 - Backend crashed — check its own logs (e.g.
docker logs, or your app's process manager) - Wrong port/address in
proxy_pass— verify it matches where the app is actually listening
sudo tail -f /var/log/nginx/error.log
504 Gateway Timeout
The backend took too long to respond.
proxy_read_timeout 90s;
proxy_connect_timeout 90s;
Increasing the timeout only masks the symptom if your backend is genuinely too slow — investigate why the app is slow (database query, external API call) as the real fix.
403 Forbidden
Nginx has no permission to serve the requested file, or explicitly denied the request.
sudo chown -R www-data:www-data /var/www/yoursite
sudo chmod -R 755 /var/www/yoursite
Also check for a missing index directive if the error occurs on the site's root:
index index.html index.htm;
404 Not Found (When the File Actually Exists)
Usually a mismatch between root in the config and the file's actual location:
sudo nginx -T | grep root
413 Request Entity Too Large
client_max_body_size 20m;
"nginx: [emerg] ... test failed" on Reload
Always test before reloading to see the exact file/line with the error:
sudo nginx -t
Site Loads but SSL Shows a Warning
Certificate might not cover the exact domain/subdomain requested, or it expired — check with:
sudo certbot certificates
Diagnostic Checklist
sudo nginx -t— is the config even valid?sudo systemctl status nginx— is the service actually running?sudo tail -f /var/log/nginx/error.log— the fastest way to find the real cause- For proxy errors, test the backend directly with
curl, bypassing Nginx entirely
Where to Look for More Detail
sudo tail -100 /var/log/nginx/error.log
sudo tail -100 /var/log/nginx/access.log
Related Articles
- How to Install Nginx on Ubuntu & Debian
- Nginx as a Reverse Proxy for Node.js/Docker Apps
- Nginx Performance Tuning: Worker Processes, Caching & Gzip
