my site goes 502 right after every deploy. proxy or app to blame?

Solved502nginxreverse-proxy7 replies · 157 views · started
Accepted solution by Wes Fontaine — ahh classic after reboots and deploys, teh classic casues are a socket path mismatch (fastcgi pass unix:/run/php/... pointing at a socket…
  1. im literally losing my mind here getting 502 Bad Gateway right after every deploy, and its starting to cost us orders.

    502 Bad Gateway

    502 Bad Gateway
    nginx
    

    The setup is Apache proxying to Gunicorn on a small VPS. CPU graphs look normal, disk isnt full. The proxy itself is clearly alive because it serves the error page. So smth behind it is dying or not answering, but what? Id appreciate a checklist from someone who has hunted these before. Detailed answers welcome, Im comfortable on the command line. what am i doing wrong??

    cry

    1
  2. hmmm for PHP-FPM, check its log for server reached pm.max_children setting. when all workers are busy, new requests queue and eventually fail. tune pm.max_children based on available RAM divided by average worker memory, not by guesswork. hope that helps :)

    13 2 helpful
  3. check teh app service right after a 502: systemctl status php*-fpm, systemctl status yourapp, or docker compose ps. If it shows resatrts or exited state, read its own logs with journalctl -u yourapp -n 200 or docker compose logs app. The real error lives there, not in teh proxy log. lmk how it goes

    9 0 helpful
  4. i come back to this trhead every week just for the drama. which version are you on??

    5 0 helpful
  5. Accepted solution

    ahh classic after reboots and deploys, teh classic casues are a socket path mismatch (fastcgi_pass unix:/run/php/... pointing at a socket name that changed), teh app not being eanbled at boot (systemctl enable yourapp), or a container listening on 127.0.0.1 inside Docker so the proxy cotnainer cant reach it 😭 bind to 0.0.0.0 in the container and use teh service name in the proxy config. good luck man!

    followed this step by step and it worked:

    ▶ How to fix Nginx 502 Bad Gateway Error

    1 9 helpful
  6. Before tuning workers, Id add basic monitoring with memory graphs. Tuning blind on a 1 GB box is guesswork; you need to see teh curve before and after.

    39 1 helpful
  7. @loose_probe-1kp yesss added a healthcheck and depends_on so the app waits for the database, plus a restart policy. Deploys no longer cause 502s. Appreciate the checklist. owe u a beer 🍺

    2 6 helpful

Reply to this topic

Sign in or create an account to reply.