>_ IzzyLab

Hands-on task

This task is step 23 of the course “Troubleshooting and recovering a Linux server”

The warehouse answers 502

hard~10 min

The inventory service is opened through nginx: http://localhost/api/stock — and people get 502 Bad Gateway. nginx itself is running and the config is valid. Find where requests are proxied and why nothing answers there, and fix it so that the response of the inventory app itself comes through the proxy again (its code is in /opt/inventory).

The Site tab shows what nginx serves on port 80: right now it's a 502 page. After the fix, hit Refresh — the inventory JSON should appear.

What you'll practise:
  • nginx
  • 502 bad gateway
  • proxy_pass
  • ss
  • background process

Topic breakdown

502 Bad Gateway means nginx accepted the request but got no answer from the upstream — the address given in proxy_pass. Diagnosis goes down the chain: in the config you find the backend's address and port, with ss -ltn you check whether anyone listens on it, and if not, you look for what exactly should be running there. Swapping the backend for the first HTTP server at hand won't do: the 502 goes away, but users get the wrong data. The right app is started in the background, detached from the terminal (setsid, nohup), so it doesn't die with the session.

What's checked

  1. the proxy returns 200
  2. the inventory app answers

What it looks like