Setting up Caddy as a reverse proxy

Last updated:

|Edit this page

We like using Caddy because it makes setting up the reverse proxy and TLS a breeze.

Terminal
docker run -p 80:80 -p 443:443 caddy caddy reverse-proxy --to app.posthog.com:443 --from <YOUR_TRACKING_DOMAIN> --change-host-header

You'll want to sub out YOUR_TRACKING_DOMAIN for whatever domain you use for proxying to PostHog. We'd suggest something like e.yourdomain.com or the like.

Make sure your DNS records point to your machine and that ports 80 and 443 are open to the public and directed toward Caddy.

If you want to use a config file instead, you can use something of the form:

:{$PORT} {
header {
Access-Control-Allow-Origin https://<your domain name>
}
reverse_proxy https://app.posthog.com {
header_up Host app.posthog.com
header_down -Access-Control-Allow-Origin
}
}

Questions?

Was this page useful?

Next article

Using Cloudflare as a reverse proxy

To use Cloudflare for reverse proxying, make sure that you're logged into your Cloudflare account, and that you've added your domain (called "website" in Cloudflare) to the account. There are two ways to do this: Using Cloudflare Workers . This is a bit more setup, but can be used on all Cloudflare plans. Using DNS and Page Rules . This is simplest method, but requires the Cloudflare Enterprise plan. Method one: Proxy using Cloudflare Workers Workers are really powerful and allow up to 10…

Read next article