In this guide
A simple guide to this issue: Nginx '502 Bad Gateway' Error. Learn why it happens, what to check first, and how to fix it.
A 502 from Nginx is rarely Nginx's fault — it is the messenger. It means the upstream service Nginx proxies to (your Node app, PHP-FPM, Gunicorn) did not return a valid response. Start with the logs.
The Error
502 Bad Gateway — nginx
Step 1: Read the Error Log
sudo tail -f /var/log/nginx/error.logconnect() failed (111: Connection refused) means your app is down. upstream timed out means it is too slow.
Cause 1: The App Process Crashed
pm2 status # Node
pm2 restart app
sudo systemctl status php8.3-fpm # PHP-FPMCause 2: Wrong upstream Address or Socket
location / {
proxy_pass http://127.0.0.1:3000; # must match your app's port
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_read_timeout 60s; # raise for slow endpoints
}Always Test Before Reloading
Run sudo nginx -t to validate the config, then sudo systemctl reload nginx. Reloading a broken config can take the whole site down.
Relevant Scaleup Infotech Services
Keep Reading
Fix React Search Results Showing the Wrong Data
Fix React search race conditions with request cleanup, cancellation, and stale-response checks. Includes code and a slow-network verification checklist.
5 min readFix Next.js Environment Variables Missing in Production
Fix missing Next.js production environment variables by checking build-time values, public prefixes, deployment settings, and the exact release artifact.
5 min readFix Laravel Queue Jobs Not Processing After Deployment
Recover Laravel queue jobs after deployment by checking the connection, queue name, workers, cached configuration, failed jobs, and restart behavior.
5 min read