Pomerium reverse proxy
Contents
- If you use a self-hosted proxy, PostHog can't help troubleshoot. Use our managed reverse proxy if you want support.
- Use domains matching your PostHog region:
us.i.posthog.comfor US,eu.i.posthog.comfor EU. - Don't use obvious path names like
/analytics,/tracking,/telemetry, or/posthog. Blockers will catch them. Use something unique to your app instead.
This guide shows you how to use Pomerium as a reverse proxy for PostHog.
How it works
Pomerium is an identity-aware proxy that sits between your users and backend services. For PostHog, you configure Pomerium to route requests from your domain to PostHog's servers with public access enabled (no authentication required).
Here's the request flow:
- User triggers an event in your app
- Request goes to your Pomerium proxy (e.g.,
e.yourdomain.com) - Pomerium matches the request to a route and checks the policy
- With public access enabled, Pomerium forwards the request to PostHog
- PostHog's response is returned to the user under your domain
Why public access? Unlike typical Pomerium use cases where you want to authenticate users, PostHog analytics should work for all visitors including anonymous users. You'll create a policy that allows unauthenticated access.
Prerequisites
- A domain with DNS pointing to your Pomerium instance
- Either a Pomerium Zero account or Pomerium Core installed
Choose your setup option
Both options accomplish the same goal. Choose based on your Pomerium deployment:
- Pomerium Zero: The managed service with a web-based UI. Use this if you want the simplest setup without managing infrastructure.
- Pomerium Core: The self-hosted version configured with YAML files. Use this if you're already running Pomerium Core or prefer configuration as code.
Option 1: Pomerium Zero
Pomerium Zero uses a web-based console for configuration. You'll create a policy and two routes.
- 1
Create a public access policy
In the Pomerium Zero console, create a new policy with public access enabled. This allows unauthenticated requests to pass through, which is required for PostHog analytics to work for all visitors.
Configure these settings:
Setting Value Name allow-allor similarPolicy Enforcement Optional Public Access Enabled in overrides section See Pomerium's policy documentation for detailed instructions.
- 2
Create the PostHog routes
Create two routes in the Pomerium Zero console, both using the public access policy you created:
Route From To Path prefix PostHog https://e.yourdomain.comhttps://us.i.posthog.comnone PostHog Assets https://e.yourdomain.comhttps://us-assets.i.posthog.com/staticReplace
e.yourdomain.comwith your subdomain. Replaceuswitheufor EU region.The assets route needs the
/staticprefix so it only matches requests for PostHog's JavaScript SDK and other static files. All other requests go to the main route.See Pomerium's routing documentation for detailed instructions.
- 3
Update your PostHog SDK
In your application code, update your PostHog initialization:
Replace
e.yourdomain.comwith your actual subdomain. Verify your setup
CheckpointConfirm events are flowing through your proxy:
- Open your browser's developer tools and go to the Network tab
- Trigger an event in your app
- Look for requests to your subdomain (e.g.,
e.yourdomain.com) - Verify the response status is
200 OKand you're not prompted to authenticate - Check the PostHog app to confirm events appear
If you see errors, check troubleshooting below.
Option 2: Pomerium Core
- 1
Add routes to your config
Add these routes to your Pomerium
config.yaml:Replace
e.yourdomain.comwith your subdomain.The
public: truepolicy allows unauthenticated access. Theprefix: "/static"ensures the assets route only matches static file requests.See Pomerium's routes documentation for more configuration options.
- 2
Reload Pomerium
Apply the configuration changes:
Terminal - 3
Update your PostHog SDK
In your application code, update your PostHog initialization:
Replace
e.yourdomain.comwith your actual subdomain. Verify your setup
CheckpointConfirm events are flowing through your proxy:
Test the proxy directly:
TerminalYou should see a
200 OKresponse without authentication prompts.Open your browser's developer tools and go to the Network tab
Trigger an event in your app
Look for requests to your subdomain
Check the PostHog app to confirm events appear
If you see errors, check troubleshooting below.
Troubleshooting
Authentication prompts appearing
If users are prompted to log in when accessing your proxy, verify your policy has public access enabled and is applied to both routes. See Pomerium's authorization documentation for policy configuration details.
404 errors on static assets
If the PostHog SDK fails to load, verify the assets route has the /static prefix configured and points to the correct domain (us-assets.i.posthog.com or eu-assets.i.posthog.com).
DNS not resolving
If your subdomain doesn't resolve, verify your DNS records point to your Pomerium instance. For Pomerium Zero, check Pomerium's networking documentation to ensure the subdomain is configured correctly.