>_ IzzyLab

Hands-on task

This task is step 19 of the course “Networking and HTTP from the terminal”

Diagnostics: 502 from the proxy

hard~10 min

nginx on port 80 works as a reverse proxy, but http://localhost/ returns 502 Bad Gateway. Find the cause and fix it so the proxy returns 200. Don't change the nginx config — fix what it proxies to. You can see the error in the Site tab too — once it's fixed, the backend's response shows up there.

What you'll practise:
  • nginx
  • 502 bad gateway
  • proxy_pass
  • upstream
  • diagnostics

Topic breakdown

A 502 Bad Gateway from nginx means the proxy itself is alive, but the upstream — what it proxies to via proxy_pass — is unreachable. Diagnosis starts from the config: you look at the backend's address and port, then check whether anyone is listening on that port (for example, via ss -ltn). The fix is to start any HTTP server on the right port and detach it from the terminal so it keeps living in the background; as soon as the upstream responds, nginx returns 200.

What's checked

  1. proxy returns 200 (backend is up)
  2. the upstream from proxy_pass responds

What it looks like