---
title: Set up Speed Insights when a reverse proxy serves several Vercel projects on one domain
description: Configure Vercel Speed Insights so it collects Core Web Vitals for every Vercel project behind a reverse proxy such as Akamai or Cloudflare.
url: "https://vercel.com/kb/fde/speed-insights-with-reverse-proxy-in-front-of-vercel"
published: 2026-11-12
last_updated: 2026-11-12
authors: Dawid Dao Xuan
---

# Set up Speed Insights when a reverse proxy serves several Vercel projects on one domain

Configure Vercel Speed Insights so it collects Core Web Vitals for every Vercel project behind a reverse proxy such as Akamai or Cloudflare.

With the default setup, the Speed Insights script request doesn't match any proxy rule, so no project receives data. Vercel recommends pointing your domain directly to Vercel, so use this guide when a reverse proxy is a requirement you can't remove.

To have an agent do this setup for you, copy the [prompt for AI Agents](#prompt-for-ai-agents) at the end of this guide.

## Overview

In this guide, you'll learn how to:

- Check whether Speed Insights works behind your reverse proxy
  
- Configure each project to send Speed Insights data through its own path
  
- Send data from all projects to a single project instead
  

## Who this guide is for

This guide covers domains where the reverse proxy, not Vercel, routes paths to projects. For example, `example.com/basket/*` goes to one Vercel project and `example.com/account/*` goes to another. The examples use two Next.js projects named `basket-app` and `account-app`.

If your projects use [Vercel Microfrontends](https://vercel.com/docs/microfrontends), use the built-in [Observability Routing](https://vercel.com/docs/microfrontends/managing-microfrontends#observability-data-routing) setting instead. Observability Routing sends each project's Speed Insights and Web Analytics data to that project and requires `@vercel/speed-insights` 1.2.0 or newer.

## Why the default Speed Insights setup fails behind a reverse proxy

The `@vercel/speed-insights` package makes two requests from the visitor's browser, both to the domain the visitor is on:

| Request     | Purpose                              |
| ----------- | ------------------------------------ |
| `script.js` | Loads the collection script          |
| `vitals`    | Sends the measured metrics to Vercel |

With the default `<SpeedInsights />` component, both requests go to a path at the root of the domain, such as `script.js`. On Vercel, the path is built at build time from a random seed, a mechanism called [Resilient Intake](https://vercel.com/docs/speed-insights/privacy-policy#resilient-intake), so each project gets a different path. Neither the package nor Vercel adds the Next.js `basePath` or any other prefix to this path.

A reverse proxy that routes `/basket/*` and `/account/*` has no rule for a root path, so the script request fails and no vitals are sent. This happens in every project behind the proxy, so none of them receive Speed Insights data.

## Before you begin

- Install `@vercel/speed-insights` and add `<SpeedInsights />` to each project, as described in the [Speed Insights quickstart](https://vercel.com/docs/speed-insights/quickstart).
  
- Enable Speed Insights in the dashboard of each project that should receive data.
  
- Make sure you can change the reverse proxy's routing rules, or work with the team that can.
  

## Check whether Speed Insights works behind your proxy

Speed Insights works when the script request succeeds. To check it:

1. Open a page from one of your projects through the reverse proxy, for example `example.com/basket`.
   
2. Open DevTools, go to the **Network** tab, and filter by `script.js`.
   
3. Reload the page and select the Speed Insights script request. The **Headers** tab shows the request URL and status.
   

With the default setup behind a reverse proxy, the request goes to a path at the root of the domain and fails, typically with a `404` status.

![DevTools Network tab on the basket page. The Speed Insights script request goes to a random path at the domain root and returns 404 Not Found.](https://images.ctfassets.net/hjgychtc108g/72Td8SOQWg3AhdeRI6ybrS/7da830ccc3883bb90dca24dfc34064bc/01-before-basket-script-404.png)

Repeat the check for every project behind the proxy. If the script request succeeds in a project, that project already receives data.

## Steps

### 1\. Choose a path prefix for each project

Use a path under the prefix that the proxy already routes to the project, so the browser requests stay inside that project's part of the domain:

| Project       | Speed Insights script            | Speed Insights vitals                    |
| ------------- | -------------------------------- | ---------------------------------------- |
| `basket-app`  | `basket/_vercel/speed-insights`  | `/basket/_vercel/speed-insights/vitals`  |
| `account-app` | `account/_vercel/speed-insights` | `/account/_vercel/speed-insights/vitals` |

A Vercel deployment serves Speed Insights only at `/_vercel/speed-insights/*` on its own root, not under a prefix. In step 3, the proxy removes the prefix before it forwards these requests.

### 2\. Set `scriptSrc` and `endpoint` in each project

Pass the paths from step 1 to the `<SpeedInsights />` component in each project's root layout. Use relative paths, not full URLs, so the browser sends both requests to the domain the visitor is on and the proxy routes them.

```javascript
import { SpeedInsights } from '@vercel/speed-insights/next'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <SpeedInsights
          scriptSrc="/basket/_vercel/speed-insights/script.js"
          endpoint="/basket/_vercel/speed-insights/vitals"
        />
      </body>
    </html>
  )
}
```
```javascript
import { SpeedInsights } from '@vercel/speed-insights/next'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <SpeedInsights
          scriptSrc="/account/_vercel/speed-insights/script.js"
          endpoint="/account/_vercel/speed-insights/vitals"
        />
      </body>
    </html>
  )
}
```

Explicit `scriptSrc` and `endpoint` values take precedence over the values Vercel sets at build time, so the paths stay the same on every deployment. You can also set them with the `VERCEL_OBSERVABILITY_CLIENT_CONFIG` variable, as described in [Dynamic configuration](https://vercel.com/docs/speed-insights/package#dynamic-configuration).

### 3\. Add reverse proxy rules for the Speed Insights paths

In the reverse proxy, forward each project's Speed Insights paths to that project's Vercel origin, and remove the project prefix from the path. These are ordinary path rewrite rules, so you can create them the same way in any proxy.

Remove the prefix in the proxy, not with a rewrite in `next.config.ts`. Vercel serves `/_vercel/speed-insights/*` as platform routes before your Next.js app runs, so Next.js rewrites never see these requests.

| Request path                        | Forward to           | Path at the origin          |
| ----------------------------------- | -------------------- | --------------------------- |
| `/basket/_vercel/speed-insights/*`  | `basket-app` origin  | `/_vercel/speed-insights/*` |
| `/account/_vercel/speed-insights/*` | `account-app` origin | `/_vercel/speed-insights/*` |

Place these rules before the rules that forward `/basket/*` and `/account/*`. Those broader rules keep the prefix, so if they match first, the origin returns `404` for the Speed Insights paths.

Let the proxy follow the `Cache-Control` headers from the origin. Vercel sends `public, max-age=2678400` for `script.js`, so the proxy can cache it, and `public, max-age=0, must-revalidate` for `vitals`, so each vitals request reaches Vercel.

For example, in a Cloudflare Worker, the Speed Insights rule runs before the page rules:

```javascript
const SPEED_INSIGHTS = /^\/(basket|account)(\/_vercel\/speed-insights\/.*)$/

export default {
  async fetch(request, env): Promise<Response> {
    const url = new URL(request.url)
    const origins: Record<string, string> = {
      basket: env.BASKET_ORIGIN,
      account: env.ACCOUNT_ORIGIN,
    }

    // Speed Insights: remove the prefix, then forward to the project's origin
    const match = url.pathname.match(SPEED_INSIGHTS)
    if (match) {
      const target = new URL(match[2] + url.search, origins[match[1]])
      return fetch(new Request(target, request))
    }

    // Pages: forward with the prefix
    const prefix = url.pathname.split('/')[1]
    if (prefix in origins) {
      const target = new URL(url.pathname + url.search, origins[prefix])
      return fetch(new Request(target, request))
    }

    return new Response('Not Found', { status: 404 })
  },
} satisfies ExportedHandler<Env>
```

### 4\. Deploy and verify

Deploy each project to production, then check each project through the reverse proxy:

1. Open a page from the project, for example `example.com/basket`, with DevTools open on the **Network** tab and **Preserve log** turned on.
   
2. Filter by `_vercel`, and confirm that the `script.js` request uses the project's prefix and returns `200`.
   
3. Switch to another tab and back, or navigate to another page. The script sends vitals when the page is hidden, so a `vitals` request with the project's prefix appears and returns `200`.
   
4. Load and leave a few pages in each project to generate data points.
   

![DevTools Network tab on the basket page, filtered by \_vercel. The script.js and vitals requests both return 200.](https://images.ctfassets.net/hjgychtc108g/4lTTI8ZfPQMZsJPsIxIn1V/d715001d64af22c2d659b405fe741beb/03b-after-basket-script-200.png)

Open **Speed Insights** in each project's dashboard, select the **Paths** tab, and confirm that the project shows data for its own paths. Data usually appears within a few minutes.

The **Routes** tab shows routes without the Next.js `basePath`, so a page at `/basket` appears as `/`. Use the **Paths** tab to see the full paths.

![Speed Insights for basket-app. The Paths tab lists /basket with a Real Experience Score of 100](https://images.ctfassets.net/hjgychtc108g/FKdTD5JE5E2DeD7i43VrR/7792bac15a5cd140ebb1b1f6d11e0792/05-dashboard-basket-app.png)

## Send Speed Insights data from all projects to one project

To see Speed Insights for the whole domain in one dashboard, point every project's `scriptSrc` and `endpoint` at the same project's prefix. For example, to collect everything in `basket-app`, use the `basket-app` paths in `account-app` too:

```javascript
<SpeedInsights
  scriptSrc="/basket/_vercel/speed-insights/script.js"
  endpoint="/basket/_vercel/speed-insights/vitals"
/>
```

The proxy rule for `/basket/_vercel/speed-insights/*` sends these requests to `basket-app`, so you don't need extra proxy rules. The `basket-app` dashboard shows `/basket` and `/account` side by side on the **Paths** tab, and `account-app` doesn't receive data. Speed Insights data points then count toward the `basket-app` project.

On the **Routes** tab, pages from different projects can share a route. For example, both home pages appear as `/`, so their data is combined there. Use the **Paths** tab to compare projects.

![Speed Insights for basket-app with data from both projects. The Paths tab lists /basket and /account](https://images.ctfassets.net/hjgychtc108g/6JTqnXMrtQPzfYNSEyNr9Z/cb11a3ecb42cfafea5f6814839ae1d3a/07-dashboard-aggregated-basket-and-account.png)

## Get accurate country data behind a reverse proxy

Speed Insights records a country for each data point. Behind a reverse proxy, Vercel needs the visitor's IP address from a header the proxy sets, and the proxy must be configured so that Vercel detects it as a proxy. Otherwise, Vercel attributes every data point to the proxy's location. [Verified Proxy](https://vercel.com/docs/security/reverse-proxy) provides this for supported providers.

| Plan       | Available option                                                               |
| ---------- | ------------------------------------------------------------------------------ |
| Hobby, Pro | Verified Proxy Lite for supported providers                                    |
| Enterprise | Verified Proxy Lite and Verified Proxy Advanced, including self-hosted proxies |

## Troubleshooting

### The `script.js` request still goes to a root path

The deployment doesn't include the new `scriptSrc` value. Check that you changed the root layout of the project that serves the page, then redeploy.

### The `script.js` request returns `404` at the prefixed path

The proxy forwards the path with the prefix, forwards it to the wrong origin, or Speed Insights isn't enabled for the project. Check that the Speed Insights rule removes the prefix and runs before the page rule for the same prefix, check which origin it forwards to, and enable Speed Insights in the project's dashboard.

### `script.js` loads but no `vitals` request appears

The script sends vitals when the page is hidden or unloaded. Switch tabs or navigate away, then check the **Network** tab again with **Preserve log** turned on. The script also doesn't send vitals from automated browsers, such as browsers controlled by Playwright or Puppeteer, or from headless browsers. Content blockers can also block the request.

### A `next.config.ts` rewrite for the Speed Insights paths has no effect

Speed Insights routes are Vercel platform routes. They're served outside Next.js routing, so a rewrite such as `/basket/_vercel/speed-insights/:path*` to `/_vercel/speed-insights/:path*` never runs. Remove the prefix in the reverse proxy instead, as described in step 3.

### Data appears in the wrong project

A broader proxy rule matches the Speed Insights path before the per-project rule. Check the rule order in the proxy.

## Prompt for AI agents

To apply this guide with an AI coding agent, copy this prompt into the agent:

```markdown
Set up Vercel Speed Insights for Vercel projects that a reverse proxy, such as Akamai or Cloudflare, serves on one shared domain in front of Vercel. The proxy routes path prefixes to projects, for example /basket/* to one project and /account/* to another.

Before you change anything, find out and confirm with me:
1. Every Vercel project behind the proxy and the path prefix the proxy routes to it.
2. Where the reverse proxy configuration lives and whether you can edit it. If you can't, write the rules for me to hand to the team that owns the proxy.
3. Whether each project keeps its own Speed Insights data, or all projects send data to one project.
4. Whether the projects use Vercel Microfrontends. If they do, stop and tell me to use Observability Routing instead of this setup.

Facts to rely on:
- The default <SpeedInsights /> component requests a random path at the domain root, such as /ded50bb4357d28b4/script.js. Vercel doesn't add the Next.js basePath or any other prefix, so the proxy has no rule for it and the request fails, usually with a 404.
- A Vercel deployment serves Speed Insights only at /_vercel/speed-insights/* on its own root. /<prefix>/_vercel/speed-insights/* returns 404 at the origin.
- Vercel serves /_vercel/speed-insights/* before Next.js routing runs, so a next.config.ts rewrite for these paths never runs.
- Explicit scriptSrc and endpoint values take precedence over the values Vercel sets at build time.

Then make these changes:
1. In each project's root layout, set scriptSrc and endpoint on <SpeedInsights /> from @vercel/speed-insights to relative paths under the project's prefix: /<prefix>/_vercel/speed-insights/script.js and /<prefix>/_vercel/speed-insights/vitals. Use relative paths, not full URLs. To send all data to one project, use that project's prefix in every project.
2. In the reverse proxy, add one rule per receiving project that forwards /<prefix>/_vercel/speed-insights/* to that project's Vercel origin and removes the prefix, so the origin receives /_vercel/speed-insights/*. Place these rules before the rules that forward /<prefix>/*. Keep the Cache-Control headers from the origin.
3. Don't add a next.config.ts rewrite for the Speed Insights paths.

When you finish, give me:
- A list of the changed files and the proxy rules.
- Steps to verify each project after deploying to production: open a page through the proxy in a regular browser, not a headless or automated one, with DevTools open on the Network tab, Preserve log on, and the filter set to _vercel. Confirm that script.js and the vitals POST return 200 under the project's prefix. The vitals request appears after you switch tabs or navigate away. Then check the Paths tab in Speed Insights in the receiving project's dashboard.
- A reminder to enable Speed Insights in the dashboard of every receiving project, and to set up Verified Proxy (https://vercel.com/docs/security/reverse-proxy) so Speed Insights records the visitor's country instead of the proxy's location.
```

## Related resources

- [Using Cloudflare and other reverse proxies with Vercel](/kb/guide/can-i-use-a-proxy-on-top-of-my-vercel-deployment): General information about using an external proxy to serve a Vercel Deployment.

## Related documentation

- [Observability](/docs/observability)

## More FDE Field Notes

- [Six enterprise redirect antipatterns](/kb/fde/six-enterprise-redirect-antipatterns): Avoid broken migration URLs and unnecessary application work. Choose the right redirect method and test changes before cutover.

- [Optimize CSS output after moving Next.js from webpack to Turbopack](/kb/fde/optimize-turbopack-css): Diagnose larger CSS after moving Next.js to Turbopack. Use the agent skill to compare route-level output, identify causes, and test targeted fixes.

- [Sitemap lastmod should track content, not deployments](/kb/fde/correct-lastmod-nextjs-sitemap): Set accurate sitemap lastmod dates in Next.js using stored content timestamps, targeted revalidation, and checks that distinguish content changes from builds.

## Reference Architecture

Choose a stack and work through the decisions behind it, with curated documentation, guides, templates, and courses to help you build.

- [Agent stack](/kb/architecture/agents): Build and operate agents with models, tools, and durable workflows.
- [Web applications](/kb/architecture/web): Choose rendering, data, authentication, and caching approaches.
- [Backends](/kb/architecture/backends): Choose a runtime, connect services, and run background work.

[Browse all stacks](/kb/architecture)

## Build with prompts

Build an app, extend an agent, or improve your project with ready-to-use prompts for your coding agent.

[Browse the prompt library](/kb/prompts) · [Read the Markdown index](/kb/prompts.md)
