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.
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
).Avoid using generic or common path names like
/analytics
,/tracking
,/ingest
, or/posthog
for your reverse proxy. They will most likely be blocked. Instead, use a non-obvious path name or something random and unique to your application that's unlikely to appear in a filter list.
Netlify supports redirects and rewrites which we can use as a reverse proxy from a custom route. In your netlify.toml
file, add a redirect like this:
[[redirects]]from = "/<ph_proxy_path>/static/*"to = "https://us-assets.i.posthog.com/static/:splat"host = "us-assets.i.posthog.com"status = 200force = true[[redirects]]from = "/<ph_proxy_path>/*"to = "https://us.i.posthog.com/:splat"host = "us.i.posthog.com"status = 200force = true
Note: If deploying SvelteKit on Netlify use
_redirects
file and place it in the project root, as redirects innetlify.toml
configuration are not supported.
/<ph_proxy_path>/static/* https://us-assets.i.posthog.com/static/:splat 200!/<ph_proxy_path>/* https://us.i.posthog.com/:splat 200!
Note: This proxy configuration works with custom domains but may not work correctly with the default
.netlify.app
domain. If you're experiencing issues with PostHog requests being blocked, ensure you're using a custom domain rather than the default Netlify domain.
Once done, set the /<ph_proxy_path>
route of your domain as the API host in your PostHog initialization like this:
posthog.init('<ph_project_api_key>', {api_host: 'https://www.your-domain.com/<ph_proxy_path>',ui_host: '<ph_app_host>',defaults: '2025-05-24',})
Once updated, deploy your changes on Netlify and check that PostHog requests are going to https://www.your-domain.com/<ph_proxy_path>
by checking the network tab on your domain.