DevOps EngineerJuniornginxlinuxreverse-proxy

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.

Level
Junior
Time
~20 min
Cost
Free

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

/etc/nginx/nginx.conf (the broken upstream)
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

Why this impresses a hiring manager

On your portfolio, this becomes

Caught a port mismatch between the nginx upstream block and the actual app port, restoring traffic through the reverse proxy

Keep going

Fix a Docker Container That Exits ImmediatelyDevOps projectDevOps roadmapStep by step to hiredDevOps interview questionsSTAR answersAll DevOps projectsProjects hub

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 →