Configuring advanced reverse proxy headers and upstream load balancing in Caddyfile

Hi everyone,

I am working on setting up a production reverse proxy environment using Caddy and running into a bit of a configuration hurdle regarding upstream load balancing and custom header forwarding (similar to architectures we explore and discuss over at cloudstream.pk

).

Current Setup:

  • Caddy acting as the primary edge reverse proxy / TLS terminator.

  • Routing traffic to multiple backend application instances running behind the proxy.

The Challenge:

While standard proxying works smoothly, I want to ensure optimal health checks, proper WebSocket connection upgrading, and accurate forwarding of client IP headers (X-Forwarded-For, X-Forwarded-Proto) under high concurrency.

What is the recommended best practice in the Caddyfile for structuring upstream blocks and handling header manipulation securely? Are there specific directives or transport configurations you rely on for robust production setups?

Would appreciate any guidance or configuration examples. Thanks in advance!