Using Railway as a reverse proxy

Last updated:

|
Warning
  1. 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.

  2. 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).

  3. 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.

Railway provides a simple way to deploy a reverse proxy for PostHog. Click the button below to deploy a reverse proxy on Railway:

Deploy on Railway

Make sure to set the POSTHOG_CLOUD_REGION variable to either us or eu depending on your PostHog cloud region.

Afterwards, configure your PostHog client to send requests through your reverse proxy.

JavaScript
posthog.init('<ph_project_api_key>', {
api_host: 'https://your-project-name.up.railway.app', // Your Railway domain
ui_host: 'https://us.posthog.com', // Or https://eu.posthog.com depending on your cloud region.
})

Questions? Ask Max AI.

It's easier than reading through 808 pages of documentation

Community questions

Was this page useful?

Next article

Using Remix API routes as a reverse proxy

If you are using Remix, you can use API routes to set up a reverse proxy. Create a file <ph_proxy_path>.$.tsx in the routes folder. For example, if your proxy path is /ph-relay-xyz123 , name the file ph-relay-xyz123.$.tsx . In this file, set up code to match requests to a custom route, set a new host header, change the URL to point to PostHog, and rewrite the response. Once done, configure the PostHog client to send requests via your rewrite.

Read next article