Debug a Production Nginx 502 Bad Gateway
A real devops problem you debug end to end in a live cloud workspace, then show on your portfolio. No tutorial, no toy app - a broken system that behaves like production.
The scenario
The website is returning 502 Bad Gateway errors. Users started reporting the issue after a recent deployment. The application backend is confirmed running, but nginx can't seem to reach it.
The broken code you start with
upstream backend {
server 127.0.0.1:8080; # the app actually listens on 3000
}
server {
listen 80;
location / {
proxy_pass http://backend;
}
}What this teaches you
What you did: Checked /var/log/nginx/error.log and saw "connect() failed" pointing at the upstream port. Compared the nginx upstream port against the actual listening port (ss -tlnp / app config) - they didn't match. Updated nginx.conf and reloaded.
Why it matters: 502 is the canonical "I can't reach what I'm proxying to" error. The reverse proxy is healthy; the upstream is unreachable or returning bad responses. Reading the error log first is the rule - 90% of 502s tell you exactly which upstream and why.
In the real world: When teams do rolling deployments, the port or address the app listens on sometimes changes between versions. If the nginx config is not updated at the same time, you get this exact 502. The safest fix is to keep the port in one shared config file that both nginx and the app read from, so they can never disagree.
What you'll practice
- Reading the nginx error log to localize a failure
- Tracing a reverse-proxy upstream to the backend port
- Reloading nginx safely after a config change
Why this impresses a hiring manager
- This is a real nginx problem teams hit in production - not a synthetic puzzle.
- It shows you can diagnose and fix a DevOps issue in a live system end to end.
- It lands on your portfolio as a scenario a hiring manager can open and click through.
Caught a port mismatch between the nginx upstream block and the actual app port, restoring traffic through the reverse proxy
Keep going
Build this project free
You're in a real cloud workspace in 30 seconds. Fix it, and it lands on your portfolio.
Start this project →