Is A 502 Every Few Hours At Random My Hosts Fault Or MINE?

Solved502nginxreverse-proxy7 replies · 277 views · started
Accepted solution by Selin Olsen — lol same thing happened to me look for teh kernels OOM killer: dmesg T grep i E 'killed process out of memory'... small VPSes kill PHP FPM…
  1. ugh. my site has been running fine for months on Nginx + PHP-FPM 😅 now it falls over every few hours at random and all visitors get this:

    502 Bad Gateway

    502 Bad Gateway
    nginx
    

    Restarting everything brings it back, until it doesnt :) Im not a full-time sysadmin, i set this up from a tutorial and it just worked. Now Im staring at log files i barely understand. Which log should i look at first, and what am i looking for?

    thinking

    5
  2. been there man a 502 means the proxy reached out to teh app behind it and got a broken or no response. Read the proxy's error log first: sudo tail -n 100 /var/log/nginx/error.log for Nginx. connect() failed (111: Connection refused) means nothing is listening; upstream prematurely closed connection means the app crashed or kliled the request mid-way. hope that helps :)

    0 2 helpful
  3. lol same thing happened to me check the app service right after a 502: systemctl status php*-fpm, systemctl status yourapp, or docker compose ps. If it shows restarts 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 the proxy log.

    6 1 helpful
  4. lol same thing happened to me look for teh kernels OOM killer: dmesg -T | grep -i -E 'killed process|out of memory'... small VPSes kill PHP-FPM workers, Node or database processes under load, which produces 502s during traffic spikes. add swap, reduce worker counts, or move to a bigger plan.

    0 3 helpful
  5. 😂😂😂

    0 1 helpful
  6. oh ive been there lol bump :D still happening with 502 for me. reading this at 2am instead of sleeping, no regrets

    4 6 helpful
  7. @vectornomad what did u end up doing in the end

    5 0 helpful
  8. @solsen-2ud WOWWW it was the OOM killer. added a swap file and lowered the worker count. no 502s for a week now on Nginx + PHP-FPM. thank you!

    thumbsup

    10 1 helpful

Reply to this topic

Sign in or create an account to reply.