When migrating legacy sites to Next.js on Vercel, you need to be careful about how you configure CDNs. Here's how to approach this:
First, it's important to understand that Vercel already includes its own Edge Network (CDN) for all deployments. Placing another CDN in front of Vercel requires caution 12.
Vercel's documentation specifically notes: "While sometimes necessary, proceed with caution when you place another CDN in front of Vercel" 2. This is because Vercel's Edge Network handles deployment updates by purging its cache globally, and an additional CDN layer can interfere with this process.
Set up your Next.js project on Vercel
Configure your legacy site's DNS
Use a reverse proxy approach
Gradual migration with path-based routing
For Next.js assets configuration
assetPrefix
in your Next.js configuration to specify where static assets are served from 3Testing and verification
DNS cutover
This approach allows for a gradual migration without downtime while leveraging Vercel's Edge Network appropriately.
Yes, you can use Vercel as a reverse proxy for your legacy sites while incrementally migrating to Next.js. This is a supported and recommended approach for zero-downtime migrations 12.
Deploy a Next.js project to Vercel
Configure rewrites to proxy requests to your legacy site
next.config.js
:module.exports = {
async rewrites() {
return [
// Proxy all requests to your legacy site by default
{
source: '/:path*',
destination: 'https://your-legacy-site.com/:path*',
},
// As you migrate sections, add more specific rewrites
// that will be matched first
{
source: '/new-section/:path*',
// This will be handled by your Next.js app
destination: '/new-section/:path*',
},
]
},
}
Point your domain to Vercel
Incrementally migrate sections
Handle cookies and authentication
Test thoroughly
This approach allows you to gradually migrate your site to Next.js while using Vercel as the primary entry point, providing a seamless experience for users during the transition 12.