YOUR WORST 502 BAD GATEWAY WAR STORIES (AND WHAT THE CAUSE TURNED OUT TO BE)

502dockerhomelabreverse-proxy5 replies · 93 views · started
  1. ugh. well. Set up a self-hosted app in a container behind a reverse proxy, opened the shiny new subdomain, and got:

    502 Bad Gateway page seriously need help here 😭

    4
  2. ahh classic check what the app binds to. Some apps listen only on 127.0.0.1 inside their container by default, so nothing outside the container can reach them even on the same network. Set it to listen on 0.0.0.0 via its config or environment variable. worked for me anyway 🤷

    12 0 helpful
  3. ahh classic the number one cause in Docker setups: teh proxy is pointing at localhost or 127.0.0.1 😅 Inside the proxy container, localhost is teh proxy itself, not the host. Put both containers on the same user-defined Docker network and point the proxy at teh service name and teh containers internal port, e.g. http://myapp:8080, not teh published host port. good luck man!

    2 2 helpful
  4. oof a few observations. Scheme mismatches cause 502s too: if the app serves HTTPS internally (common for some dashboards) and the proxy talks plain HTTP to it, or vice versa, teh handshake fails. Either point the proxy at https:// (and allow the self-signed cert) or switch the app to plain HTTP behind the proxy. and if the app takes time to start, a health check plus depends_on keeps the proxy from hitting it too early.

    1 2 helpful
  5. network mode host makes the localhost approach work and some people swear by it for simplicity... its valid in a homelab, but you lose the isolation and port-conflict protection that bridge networks give u, sooo Id still lean toward a shared user-defined network.

    2 1 helpful
  6. Test from the proxys point of view, not yours:

    docker exec -it <proxy-container> sh
    wget -qO- http://myapp:8080
    

    worked for me anyway 🤷

    4 6 helpful

Reply to this topic

Sign in or create an account to reply.