🎯 Mission Briefing: 502 Bad Gateway
The shop's page loads, but the product list stays empty: every request to /api/ ends in 502 Bad Gateway. Last night the shop's API, shop-api, was upgraded to version 2.0. A support ticket is waiting for you in ~/ticket-5120.txt.
How the shop works
browser ──► nginx :80 ─┬─► / files from /var/www/shop
└─► /api/… passed on to shop-api (proxy_pass)
nginx doesn't make the product list itself. Requests for /api/ it passes on to the app behind it — nginx is a reverse proxy here. 502 Bad Gateway means nginx itself is fine, but it got no answer from the app.
Investigation toolkit
curl -I http://localhost/api/products # What does the API answer?
sudo tail /var/log/nginx/error.log # nginx says why, and where it tried to connect
systemctl status shop-api # Is the app running at all?
sudo ss -tlnp # Which port does it really listen on?
cat /etc/nginx/sites-available/shop # Where does nginx send /api/?
Fix and verify
Make nginx and the app agree on the port: point proxy_pass at the port the app uses now, or set the old port back in the app's configuration.
sudo nginx -t && sudo systemctl reload nginx # after a change to nginx's configuration
sudo systemctl restart shop-api # after a change to the app's configuration
curl http://localhost/api/products
💡
Connection refusedin the error log means nothing listens where nginx tried to connect. Compare theupstream:address in the log with whatss -tlnpshows.