Preserving public hostname for Next.js redirects behind a reverse proxy on Vercel

Problem

We have a Next.js app deployed on Vercel, but it’s reached via an external edge/proxy layer that routes requests from a public domain (e.g., myapp.com) to a Vercel origin host (e.g., myapp.vercel.com). After upgrading to Next.js and moving our logic into proxy.ts, we hit two issues:

Current Behavior

  1. In proxy.ts, NextResponse.redirect() requires absolute URLs.

Error: URL is malformed … use only absolute URLs

  1. In production, request.url and request.nextUrl appear to be anchored to the origin host (myapp.vercel.com), not the public host. So any redirects end up in myapp.vercel.com instead of myapp.com.

We tried relying on X-Forwarded-Host as the public host signal, but in our setup it appears to be overwritten/normalized before it reaches the Vercel runtime (we see it equal to the origin host).

Question

What’s the recommended Vercel approach to preserve the end-user host for redirects in this architecture?

  • Is there a specific header we should inject at the proxy layer that Vercel will preserve reliably (e.g., a custom X-Public-Host), or a documented way to ensure X-Forwarded-Host arrives unchanged?
  • Is there a standard Vercel config / header behavior we should enable for reverse-proxy scenarios so Next.js sees the public host?
  • Any best-practice pattern for Next.js Proxy redirects behind a separate CDN/edge proxy?