Back to all

nextjs-request-url-proxy-redirect

by Jason Cochran

00Feb 6, 2026Visit Source
Fix for NextResponse.redirect going to wrong host (localhost:8080) on Railway, Vercel, or containerized deployments. Use when: (1) redirects work locally but go to localhost in production, (2) console shows ERR_CONNECTION_REFUSED to localhost:8080 or similar internal URL, (3) using `new URL(path, request.url)` for redirects in Next.js API routes or middleware. The fix is to use NEXT_PUBLIC_APP_URL environment variable instead of request.url as the base URL.