Note: The following self-hosted proxy isn't provided by PostHog, so we can't take responsibility for it! If unsure, we recommend using our managed reverse proxy.
Note: If you are using the EU cloud then use
eu
instead ofus
in all domains (e.g.us.i.posthog.com
->eu.i.posthog.com
)
Pomerium is an identity-aware proxy that can be used to securely proxy traffic to PostHog. This guide will show you how to configure Pomerium as a reverse proxy for PostHog.
Set up with Pomerium Zero
The assumption is you've already set up Pomerium Zero.
1. Create an Optional Allow All Policy
- Log in to Pomerium Zero.
- Click on Manage -> Policies in the side bar.
- Click the New Policy button to create a new policy.
- Name the policy
allow all
or something similar. - Set the Policy Enforcement field to
Optional
. - In the Overrides section, enable Public Access.
- Click the Save Policy button to save the policy.
- The
allow all
policy has been created.
2. Create the main PostHog Route
- Click on the New Route button to create a new route.
- Select Custom Route from the list of route types.
- Name the Route PostHog
- Set the From field to, e.g.
https://e.some-name.pomerium.app
- Set the To field to
https://us.i.posthog.com
. - In the Policies drop down, select the
allow all
policy created so the analytics will run for everyone. - Click the Save Route button to save the route.
3. Create the PostHog Assets Route
- Click on the New Route button to create a new route.
- Select Custom Route from the list of route types.
- Name the Route PostHog Assets
- Set the From field to, e.g.
https://e.some-name.pomerium.app
- Set the To field to
https://us-assets.i.posthog.com
. - In the Policies drop down, select the
allow all
policy created so the analytics will run for everyone. - Click on the Path Matching link in the edit route side bar.
- Set the Prefix field to
/static
.
- Click the Save Route button to save the route
Pomerium Zero is now configured to proxy PostHog.
Set up with Pomerium Core
Assuming Pomerium Core is set up, open your config.yaml to configure Pomerium to proxy requests to PostHog by adding the following routes to your Pomerium config file:
routes:- from: https://e.some-name.pomerium.appto: https://us.i.posthog.compolicy:- allow:or:- public: truename: "PostHog"- from: https://e.some-name.pomerium.appto: https://us-assets.i.posthog.comprefix: "/static"policy:- allow:or:- public: truename: "PostHog Assets"# rest of your configuration
Use the Pomerium URL in your PostHog initialization
Once everything is configured, set the the API host to e.g. https://e.some-name.pomerium.app
in your PostHog initialization like this:
posthog.init('<ph_project_api_key>',{api_host: 'https://e.some-name.pomerium.app',})