Scenario
nginx answers 502 Bad Gateway
nginx answers, but /api/ returns 502. Both nginx and the backend are running. Find what sits between them and bring the answer back.
The orders backend has moved to a new machine. nginx sits in front of it and forwards requests for /api/. Since the move the monitoring is red: /api/ returns 502. The person who did the move said only that "everything is running" and left on holiday. The machine is yours.
The symptom
nginx itself is up and answering. So is the backend, if you believe its init script. And there is no answer.
$ curl -s -o /dev/null -w '%{http_code}\n' http://localhost/api/
502
$ curl -s http://localhost/api/
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.24.0 (Ubuntu)</center>
</body>
</html>
$ sudo service orders-api status
orders-api is running (pid 25)The 502 page is drawn by nginx itself: the request reached it, and something went wrong after that. The backend's init script says "running", and that is true, but true only about the process: it is alive. Whether it can be reached, the status does not know.
What you have to end up with
Four conditions. http://localhost/api/ through nginx returns status 200 and the string orders-api ok. The backend still listens on the unix socket /run/orders/api.sock and answers through it: moving it to a TCP port or stopping it is not a repair. The site configuration
Finish this lesson with a free account
This lesson is free once you sign in. Create an account to keep reading and open the lab.
Already have an account? Sign in