Setting up Caddy as a reverse proxy

Last updated:

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

In Cloudflare, create a new CNAME record for your domain. It should point to app.posthog.com or eu.posthog.com depending on your region, and have proxy enabled (e.g. CNAME, e, app.posthog.com, proxy enabled ). Finally, use Page Rules to change the Host header to app.posthog.com or eu.posthog.com depending on which PostHog region you are using. Cloudflare does require your domain to be hosted with them, and using them does more than just proxying requests, such as blocking traffic from…

Read next article