Using Vercel rewrites as a reverse proxy

Last updated:

|Edit this page

On this page

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 of us in all domains (e.g. us.i.posthog.com -> eu.i.posthog.com)

Vercel supports rewrites which we can use as a reverse proxy. Create a vercel.json file and add a rewrites object from the /ingest route.

JSON
{
"rewrites": [
{
"source": "/ingest/static/:path*",
"destination": "https://us-assets.i.posthog.com/static/:path*"
},
{
"source": "/ingest/:path*",
"destination": "https://us.i.posthog.com/:path*"
}
]
}

Some frameworks, like SvelteKit and Astro, require a hungrier regex pattern like:

JSON
{
"rewrites": [
{
"source": "/ingest/static/:path(.*)",
"destination": "https://us-assets.i.posthog.com/static/:path*"
},
{
"source": "/ingest/:path(.*)",
"destination": "https://us.i.posthog.com/:path*"
}
]
}

Note: Some frameworks, like T3 app, don't support Vercel rewrites well. If neither of these options work, we recommend trying another proxy method.

Once done, set the /ingest route of your domain as the API host in your PostHog initialization like this:

JavaScript
posthog.init('<ph_project_api_key>',
{
api_host: 'https://www.your-domain.com/ingest',
ui_host: '<ph_app_host>'
}
)

Once updated, deploy your changes on Vercel and check that PostHog requests are going to https://www.your-domain.com/ingest by checking the network tab on your domain.

Setup video

Questions?

Was this page useful?

Next article

Historical migrations overview

Historical migrations refer to ingesting and importing past data into PostHog for analysis. This includes: Migrating from a different tool or platform like Mixpanel , Amplitude , Heap , or LaunchDarkly . Migrating from a self-hosted PostHog instance to PostHog Cloud . Migrating from one PostHog Cloud instance to another , for example US -> EU. Adding past data from a third-party source into PostHog. What about exporting data from PostHog? Use our batch export feature to export data from…

Read next article