This article is the first one of the in-depth series about self-hosted Next.js and the challenges around it.
We’ve been big fans of server-rendered React since 2016. Its performance and ability to combine the benefits of server rendering with highly dynamic client-side applications have made it a go-to choice for web development.
As server-side rendering (SSR) and static site generation (SSG) gained mainstream adoption, one thing became clear: reinventing a custom React framework for every project wasn’t practical or scalable. Next.js emerged to solve that problem and quickly became the framework of choice for building React applications.
Its popularity grew so rapidly that a dedicated hosting platform emerged from the same team behind the framework: Vercel. Since the early days of Docker-based deployments, Vercel has steadily strengthened its position as the preferred hosting platform for Next.js. Today, it’s almost synonymous with deploying Next.js applications.
We love Vercel as much as we love Next.js. But it’s not always the right hosting solution. Cost considerations, existing cloud infrastructure, specific architectural requirements, or limitations of serverless environments can all make alternative hosting options a better fit.
In this article series, we’ll share our hands-on experience with Next.js deployments and explore when and how to self-host Next.js applications and websites. We’ll also look at the available Vercel alternatives, with a focus primarily on AWS and Cloudflare, sharing practical deployment experience, architectural considerations, and the trade-offs of each approach.
Can you self-host a Next.js application?
Yes. Next.js is an open-source React framework that can be deployed on your own infrastructure without relying on Vercel. You can run a Next.js application on a traditional Node.js server, deploy it in a Docker container, or use cloud infrastructure such as AWS and Cloudflare.
Next.js provides a standalone output mode (output: 'standalone') that simplifies self-hosted deployments by generating a minimal production-ready server along with the required dependencies.
Depending on your application’s architecture, you can choose from several deployment approaches:
- Node.js server: Run your Next.js application as a persistent Node.js process on a virtual machine or dedicated server.
- Docker containers: Package your application and its dependencies into a container and deploy it using services such as AWS ECS or Kubernetes.
- Serverless infrastructure: Deploy application functions using cloud platforms that support Next.js or compatible deployment adapters.
- Edge infrastructure: Run supported Next.js functionality closer to end users using platforms such as Cloudflare Workers.
However, self-hosting Next.js involves more than simply deploying the application. Teams also need to consider routing, caching, image optimization, scaling, load balancing, monitoring, and infrastructure maintenance.
The right deployment strategy depends on your application’s requirements, expected traffic, existing infrastructure, and the level of operational control your team needs.
Below, we explain why companies choose to self-host Next.js, what a migration from Vercel involves, and how AWS and Cloudflare compare.
Why choose alternative Next.js hosting
Let’s not forget that Next.js is an open-source project, and its authors and developers go the extra mile to ensure it does not become a proprietary framework. Sure, Next.js is opinionated—and some of those strong opinions align closely with how Vercel functions—but it is meant to be hosted wherever you like, whether that’s on a Vercel competitor, in your own cloud, or even on your laptop.
In our opinion, among several possible reasons, the two biggest limiting factors are:
- Your company (or client) is tied to a particular cloud provider, such as AWS.
- A serverless runtime isn’t suitable for your application requirements.
The first reason is relatively straightforward. It may be driven by company policy, existing cloud infrastructure, or the need to keep the Next.js application close to internal services, databases, and other systems. The second is more nuanced.
Serverless is excellent for handling variable workloads and sudden traffic spikes (think Black Friday). However, depending on the workload, it can be considerably more expensive than running traditional servers, where infrastructure costs are often easier to predict and manage. There are also technical challenges that require additional attention, including database connections in serverless environments, cold starts, execution time limits, and runtime constraints.
Meanwhile, Edge computing is gaining traction, with technologies such as Next.js Middleware and Cloudflare Workers bringing code execution closer to end users. With adapters like OpenNext, Next.js applications can now run on Cloudflare Workers as well. Edge runtimes offer interesting possibilities, but they also introduce their own limitations, particularly around runtime compatibility, available APIs, and execution environments.
To understand the differences, it’s worth distinguishing between three approaches:
- Serverless: Functions run on demand, with infrastructure managed by the provider. They can scale automatically but may introduce cold starts and execution constraints.
- Edge: Code executes closer to users geographically, typically within distributed runtimes that come with specific API and execution limitations.
- Traditional servers: Long-running application processes that give developers greater control over the execution environment, resource allocation, and application lifecycle.
Each approach has its place. But traditional servers remain a proven, independent hosting option that gives teams greater control over their infrastructure and reduces dependence on a particular hosting provider.
This series is particularly relevant for engineering teams looking to optimize hosting costs at scale, companies already invested in AWS or other cloud infrastructure, and businesses that need greater control over their application architecture. It’s also aimed at developers running Next.js applications with persistent processes, specific runtime requirements, or workloads that don’t fit neatly into a serverless model.
Whether you’re looking to reduce infrastructure costs, avoid vendor lock-in, or simply choose a hosting setup that better fits your technical requirements, understanding the alternatives to Vercel can help you make a more informed decision.
Migrating from Vercel to self-hosted Next.js
Moving away from Vercel doesn’t mean rebuilding your Next.js application from scratch. In most cases, the framework itself remains the same, while the deployment architecture, infrastructure, and parts of the application configuration need to be adapted. A migration from Vercel to self-hosted Next.js may involve setting up a Node.js server or Docker containers, configuring environment variables, replacing Vercel-specific integrations, and rethinking caching, image optimization, and request handling.
The complexity largely depends on how deeply your application relies on Vercel’s platform-specific features. For teams looking to reduce hosting costs, consolidate cloud infrastructure, or gain greater control over their deployment environment, migrating to AWS, Cloudflare, or another hosting provider can be a practical next step. The key is to evaluate platform dependencies before migration and ensure that critical Next.js features continue to work as expected in the new environment.
Best cloud platforms for self-hosting Next.js: AWS vs Cloudflare
In practice, two cloud platforms come up most often when teams look beyond Vercel:
AWS: The natural choice for companies already running their infrastructure on AWS. It supports every approach, from serverless functions to containers and traditional servers, and keeps your Next.js application close to existing databases and internal services. The trade-off is more setup and infrastructure to manage.
Cloudflare: An edge-first platform that runs Next.js on Cloudflare Workers across its global network, through adapters like OpenNext and, more recently, Cloudflare’s own vinext. It offers low latency and simple pricing, but comes with the runtime limitations typical for the edge.
| Criteria | AWS | Cloudflare |
|---|---|---|
| Deployment approach | EC2, ECS, AWS App Runner, Lambda, and container-based deployments | Cloudflare Workers with OpenNext |
| Runtime environment | Full Node.js runtime on EC2 and containers; runtime constraints on serverless services | Workerd runtime with compatibility features and certain Node.js APIs |
| Architecture | Regional cloud infrastructure with configurable global distribution | Globally distributed, edge-first infrastructure |
| Server-side rendering (SSR) | Full support with a standard Node.js runtime | Supported through OpenNext, subject to runtime compatibility |
| Static site generation (SSG) | Fully supported | Supported |
| Incremental Static Regeneration (ISR) | Supported; caching and coordination depend on deployment architecture | Supported through OpenNext, with platform-specific caching considerations |
| Caching | Flexible configuration using CloudFront, application-level caching, and external cache services | Integrated CDN caching and Cloudflare caching services |
| Image optimization | Can use Next.js Image Optimization with a compatible Node.js deployment or external image services | Requires compatible image optimization configuration, such as Cloudflare Images or an external service |
| Scaling | Configurable autoscaling through services such as EC2 Auto Scaling and ECS | Automatically scales across Cloudflare’s global network |
| Infrastructure control | High control over servers, networking, compute, and deployment architecture | Less control over the underlying runtime and execution environment |
| Pricing model | Pay-as-you-go, based on compute, storage, bandwidth, and other services | Usage-based pricing, including Workers requests and CPU time, depending on the plan |
| DevOps complexity | Higher, particularly with custom infrastructure and container orchestration | Generally simpler infrastructure management, but requires familiarity with Workers and OpenNext |
| Best suited for | Applications requiring full Node.js compatibility, custom infrastructure, and integration with existing AWS services | Applications prioritizing global edge execution, low-latency delivery, and managed infrastructure |
For a closer look at managed and open-source options for deploying Next.js on AWS, including AWS Amplify, SST, and Flightcontrol, see our overview of Next.js hosting options.
What this series covers
Rather than covering everything in one lengthy guide, we’ve decided to break the topic down into a series of focused articles, each drawing on our hands-on production experience.
Let’s break this series down to a series of more focused articles in building Next.js-powered digital products, and we’re excited to share our practical insights, lessons learned, and real-world solutions.
Let’s explore each topic in more detail with the technology enthusiasts at FocusReactive, a Next.js consultancy and web development agency.
- When Vercel isn’t the right fit: limitations and alternatives
- Standalone Next.js: when serverless is not an option
- CDN caching for self-hosted Next.js websites
- Next.js caching: ISR, PPR, and edge-level performance
- Next.js redirects: a developer’s guide
Exploring Next.js hosting alternatives for your project? Talk to our Next.js team about the setup that fits your infrastructure and budget.
Maksim Hodasevich
Oleg Proskurin