Hosting Next.js:
There Is Life Beyond Vercel
Last edited:
Let's bust a myth right away: Vercel is not the only way to host a Next.js application. There are plenty of options to share your app with the world. Some of them come with limitations, but those might be perfectly fine for your use case. This article gives you an overview, with the pros and the cons, so you can make an informed decision.
A while ago I built a small site called Hosting Next.js to collect my notes, guides and comparisons on this topic. This article bundles that content in one place, so you can read it from top to bottom:
- How Next.js runs on Vercel and why that matters
- Your self-hosted options: static export, Node.js server and Docker
- Thinking about architecture before you deploy
- Providers: Vercel, SST (OpenNext), Fly.io and Google Cloud Run
- What is changing with the Deployment Adapters API
How Next.js runs on Vercel
Before you decide how to host your Next.js application, it is important to understand how hosting on Vercel works. In the end, this is the solution every other option gets compared to.
Vercel is the company behind Next.js, and Vercel owns a very sophisticated hosting infrastructure. Unlike other frameworks (e.g. Remix or Nuxt), the Next.js team can and does solve problems (performance, caching, etc.) with that infrastructure. That is probably the reason why so many developers assume Next.js can only be hosted on Vercel.
When you deploy to Vercel, your app runs as a distributed application. Some parts of it run as serverless functions, other parts run as edge functions, and none of it runs as a single Node.js process on a single server (which is what happens when you host via Docker, for example).
An example: Middleware
Middleware is a good example of what that means. It allows you to “[…] run code before a request is completed” (Next.js docs).
On Vercel, middleware historically ran on the edge network, close to your users. The request gets modified there and is then passed on to the next stages. That is also why middleware used to be limited to the subset of APIs in the edge runtime.
When you self-host Next.js via Docker or as a Node.js server, your middleware code still runs, but it runs inside your Node.js process and not close to your users on a global network.
Note: with Next.js 16 middleware.ts is deprecated in favor of
proxy.ts, which runs exclusively in the Node.js runtime. The point
still stands: where code runs depends on your hosting platform.
Vercel vs. OpenNext vs. Docker
The only self-hosted option that tries to replicate this distributed infrastructure is OpenNext (e.g. with SST on AWS). The following table, heavily inspired by the OpenNext comparison, gives you an overview of where things run:
| Infrastructure feature | Vercel | OpenNext | Docker |
|---|---|---|---|
| Function splitting | ✅ | ✅ | ❌ |
| Multiple deployment targets1 | ✅ | ✅ | ❌ |
| Serverless | ✅ | ✅ | (❌)2 |
| External middleware | ✅ | (✅)3 | ❌ |
| External image optimization | ✅ | ✅ | ❌ |
| Edge runtime support | âś… | (âś…)4 | (âś…)5 |
| ISR | âś… | âś… | âś… |
| On-demand revalidation | âś… | âś… | âś… |
Don’t conclude too quickly that Docker is not an option. The table only shows where feature-related code runs. Your Next.js app runs just fine in a Docker container and supports all Next.js features. You only have to extend the default config once you start to scale horizontally. More on that below.
Your self-hosted options
There are three ways to host Next.js yourself, ordered here from the most limited to the most flexible.
Static export: limited features, awesome to cache
The static export turns your Next.js app into a single-page application (SPA). It basically makes Next.js a static site generator:
// next.config.js
module.exports = {
output: "export",
//... additional Next.js config
};This comes in handy if you are migrating an existing SPA to Next.js, or if you just want to build a static website with a bit of interactivity. You still benefit from route-based optimization, which makes client-side page loads faster, and you can still move to running Next.js on a server later.
Since Next.js is a server-first framework, you lose quite a few built-in features, though:
| Next.js feature | Static export | Node.js server / Docker / Vercel |
|---|---|---|
| Client Components | âś… | âś… |
| Server Components | âś… | âś… |
| Image Optimization | (âś…)6 | âś… |
| Route Handlers | (âś…)7 | âś… |
| Dynamic Routes | (âś…)8 | âś… |
| Middleware / Proxy | ❌ | ✅ |
| Caching and ISR | ❌ | ✅ |
| Cookies | ❌ | ✅ |
| Rewrites | ❌ | ✅ |
| Redirects | ❌ | ✅ |
| Headers | ❌ | ✅ |
| Draft Mode | ❌ | ✅ |
| Server Actions | ❌ | ✅ |
The upside: what you deploy are only static HTML, CSS and JS files. You can cache everything on a CDN and host it almost anywhere for little to no money.
Node.js server: full features, doesn’t scale well
Running Next.js as a Node.js server is the easiest way to self-host it with
the complete feature set. You basically run npm run build and
npm run start.
The idea is to keep the setup and the number of tools as small as possible: Node.js runs directly on your server. When your code changes, your CD pipeline SSHs into the server, builds the application and restarts the Node.js process.
To keep the process alive after you close the SSH connection, the tool of choice usually is PM2. This is what a PM2 ecosystem file for Next.js could look like:
// ecosystem.config.js
module.exports = {
apps: [
{
name: "nextjs",
script: "npm",
args: "start",
instances: 1,
autorestart: true,
watch: false,
env: {
NODE_ENV: "production",
},
},
],
};Run pm2 start ecosystem.config.js and your app is up. Configure PM2 to start
your apps on server boot and you are good to go. You still need a
proxy to serve the app under your domain on port 80/443.
So far, so simple. But having the runtime installed directly on your server doesn’t scale or maintain well:
- How do you upgrade Node.js?
- What if another app on the same server needs a different Node.js version?
- What if an OS update breaks one of your app’s dependencies, and how do you roll back?
A dockerized application solves all of these problems and gives you a more consistent environment across your stages. Which brings us to …
Docker: probably your best choice
Unless you go the serverless route with SST, most providers
require you to dockerize your Next.js application anyway. Fortunately, it is
pretty straightforward. The official
with-docker example
gives you the two files you need: a
Dockerfile
and a
.dockerignore.
On top of that, enable the standalone output mode. It makes your build fully self-contained, so only the files your app actually uses end up in the image:
// next.config.js
module.exports = {
output: "standalone",
//... additional Next.js config
};Run docker build . in your project root to check that the image builds.
Getting started is easy – scaling is not
Skill issue. Just dockerize your Next.js application, bro!
— Random internet bro
With a single container running, all features work as expected. But once you scale horizontally, you will run into problems with ISR (incremental static regeneration). The ISR cache is file-based, so depending on your load-balancing strategy, users might see a different content state on every refresh.
To fix this, you have to configure a custom cache handler that all instances share:
// next.config.js
module.exports = {
output: "standalone",
cacheHandler: require.resolve("./cache-handler.js"),
cacheMaxMemorySize: 0, // disable default in-memory caching
//... additional Next.js config
};Which cache handler you use is up to you. A popular Redis-based option is @neshca/cache-handler (see the implementation example). Check that the package you pick supports your Next.js version before you commit to it.
Thinking about architecture
Before you YOLO-deploy your Next.js app on a $3.99 VPS, take a few minutes to think about the overall architecture. Since you are not on Vercel, you lose all the nice things that come with it, and you have to replace some of them yourself.

Example architecture of a self-hosted Next.js application: a DNS/CDN layer in front of a VPS running Next.js, a proxy (e.g. Caddy) and an image optimizer (e.g. ipx) as Docker containers.
DNS & CDN
Maybe not relevant for your hobby side project, but for a “professional” project you should think about DDoS protection and a CDN caching your assets. Well-known providers like Cloudflare or Bunny often bundle both, and most of them have a free tier.
Media handling
Unless your app only contains a handful of images, you should not rely on the built-in Next.js image optimization (based on sharp). It puts extra load on your server. Use a custom image loader with an image and video optimization platform instead. The Next.js docs have a list of recommended providers. Or self-host an optimizer like ipx in a separate container.
Proxy
If you go the Docker or Node.js route on your own server, you need a proxy/app server that routes traffic to your Next.js app. Popular choices are NGINX and Caddy. Caddy is a bit more user-friendly, since it handles TLS certificates for you. NGINX is more performant but heavier on the initial configuration. If you’re curious, I wrote about my own Docker, GitLab and Caddy setup.
DIY or provider?
Once you have decided to self-host, the next decision is whether you run the app on your own server (e.g. a VPS) or let a provider host the container for you.
DIY: VPS + Docker + proxy is usually the most affordable way to host Next.js. That comes at a cost, though. If you don’t want to SSH into your server every time your code changes, you need at least a basic CI/CD pipeline.
- âś… affordable: starts at around $5/month
- âś… you learn a lot about infrastructure and server setup
- ❌ you have to build the CI/CD pipeline yourself
- ❌ server setup, security and maintenance are on you
- ❌ you have to set up a proxy server
Provider: for your hobby blog or personal website, a VPS is usually good enough. For a “professional” project there are few reasons not to pick a provider that hosts your dockerized app, especially since many of them offer a free tier to try them out.
- âś… no server setup, maintenance or server security to deal with
- ✅ the provider’s CLI usually makes the CI/CD pipeline simple
- âś… scaling is usually handled for you
- ❌ more expensive than a VPS
Providers
I deployed the same sample app to each of the following providers to get a feel for them. Here is what I found.
Vercel
Vercel comes with a bag stuffed with features. If you want to start your project as soon as possible, iterate quickly and just ship, Vercel is the way to go. You get a zero-configuration hosting environment: push your code and get a preview deployment for every branch.
Compared to self-hosting, you don’t have to worry about infrastructure security, scaling, asset caching and so on. To name a few of the things you get:
- DDoS mitigation
- Firewall
- Edge network: a CDN on steroids đź’Š
- Image optimization
- and a lot more …
Pricing: you should know what you are doing
The pricing of Vercel is quite a chapter, which makes it hard to estimate costs upfront. For a new commercial project (the Hobby plan is for non-commercial, personal use only), costs initially scale with your team size: $20/month per seat on the Pro plan, for everyone who needs access, e.g. to comment on preview deployments. After that, usage-based quotas kick in, which can be confusing if you are new to serverless.
Vercel’s pricing structure and bills are a hot topic on X 🌶️. So it can’t be emphasized enough: if you use Vercel, know the pitfalls and understand how the features you ship affect your monthly bill. A few tips:
- Host as few static files as possible. Bandwidth is expensive on Vercel, so keep your
publicdirectory close to empty and serve files and images from a dedicated CDN. - Use a dedicated image service. Vercel image optimization (especially beyond 5,000 images) is not cheap and eats into your bandwidth. Check the alternatives or self-host your image optimizer.
- Avoid long-running serverless functions. Every invocation and every second of execution time counts against your quota. Reduce invocations and optimize execution time (timeouts, faster DB queries, etc.).
- Activate Spend Management. On Pro plans, Spend Management notifies you at certain thresholds and, in the worst case, pauses your app. Either way, it caps your monthly bill.
For a deep dive, check out the Vercel docs on how to manage and optimize usage.
To be fair: people give Vercel a harder time than it deserves. The developer experience is unmatched, and global availability, the integrated features and the scalability might be exactly what your application needs.
SST (OpenNext)
SST backs OpenNext, an open source project that lets you “split the Next.js output, enabling selective deployment to different targets such as AWS Lambda, Cloudflare Workers, or Amazon ECS” (OpenNext docs). In other words: it runs Next.js as a distributed, serverless application outside of Vercel. That makes it unique among all the options in this article.
OpenNext
transforms the Next.js build output
into a format that can be deployed to AWS. Run sst deploy in your project
directory and SST creates all the required AWS resources (S3 buckets, Lambda
functions, CloudFront, etc.) for you. You need a
properly set up AWS account for that.
Since your app runs on AWS, you don’t really have to worry about scaling, only about your AWS bill. The upside is usage-based pricing. For reference: SST describes an app with 1,000 daily active users running on AWS for about $6/month. Not a Next.js app, but it gives you a rough idea.
The small drawback: the OpenNext team has to play catch-up with the Next.js core team. When Next.js adds a new infrastructure feature, it can take a while until OpenNext supports it. So don’t expect to always be on the bleeding edge.
Fly.io
Fly.io is a nice sweet spot between a fully managed platform like Vercel and a
fully self-managed server. Once your app is dockerized,
run fly launch / fly deploy in your project directory and you get a
dashboard with live logs, certificate and secrets management, etc.
Scaling is included. You can deploy your app to more than 30 regions to serve it close to your users. Scaling is a single CLI command, and you configure how your app scales in its TOML config file. The autoscaler shuts down machines when there is no (or too little) traffic, so you don’t have to worry much about costs. You can even scale to zero and only start machines when requests come in. According to Fly.io, machines “boot and respond to web requests in 250ms or less”, so paused machines can be a viable option.
But don’t get excited too soon: since you run multiple Docker containers, you still need a custom cache handler to keep the ISR cache in sync.
That’s where Fly.io’s
private networking
comes in handy. Spin up a Redis server
that is only reachable by your other apps via the internal DNS
<app-name>.internal (e.g. redis://my-redis-server.internal:6379). The same
goes for other services you might need next to Next.js, like a database or
a queue for larger async workloads.
Pricing is truly pay-as-you-go. Have a look at the pricing for started machines and you’ll see that hosting Next.js on Fly.io can be quite affordable.
Google Cloud Run
With Cloud Run, Google offers a convenient way to run your Next.js app as a
Docker container. Once your Google Cloud account is set up, run
gcloud run deploy in your project directory. A
proper Docker setup is not required, but
it reduces the size of the generated image.
Scaling is included as well: Google scales your service based on CPU utilization and concurrent requests per instance. In the context of Next.js, that comes with the familiar caveat: multiple instances mean you need a custom cache handler to keep the ISR cache in sync.
The smallest Memorystore Redis instance on Google Cloud has 1 GB and starts at around $35/month (depending on the region). Make sure your Cloud Run service has VPC access so it can reach the Redis instance.
Technically, you could disable autoscaling (and skip Redis) and enjoy the free tier while your project is new. Otherwise, around $35/month is your starting point.
What is changing: Deployment Adapters
Many of the pain points above exist because Next.js never had an official
contract between the framework and the hosting platform. Since 2016, Next.js
has offered self-hosting via a custom server, next start, standalone builds
and static exports. But serverless platforms like Netlify or Cloudflare had to
reverse-engineer undocumented build manifests, patch next.config and shim the
Next.js server to make things work.
In April 2025, Vercel posted an RFC for a Deployment Adapters API to change that. Its main goals:
- Serverless compatibility: a clear adapter API, so platforms like Netlify, Cloudflare and AWS Lambda can deploy Next.js without custom hacks.
- A uniform deployment experience: Vercel and every other host use the exact same adapter hooks, so the behavior is identical across environments.
- Fixing provider pain points: signals for background work (e.g. when cache revalidation is done), official config overrides instead of patches, a structured and versioned build output instead of undocumented JSON files, and no need to load the full Next.js server for every entry point.
Netlify, Cloudflare, AWS Amplify and the OpenNext community worked with Vercel
on the API, and Next.js 16 shipped it as an alpha. An adapter hooks into
the build with modifyConfig (before the build) and onBuildComplete (after
the build, receiving a structured manifest of routes, functions and assets).
Using one is a single config option:
// next.config.js
const nextConfig = {
experimental: {
adapterPath: require.resolve("./my-adapter.js"),
},
};
module.exports = nextConfig;If this API stabilizes, the gap between Vercel and everyone else should shrink a lot, and projects like OpenNext won’t have to play catch-up as much. Have a look at the adapters section of the Next.js docs for the current state.
So, which one should you pick?
There is no single right answer, but here is a rough guide:
- You want to ship fast and not think about infrastructure: Vercel. Just keep an eye on your bill.
- Your app is mostly static: a static export. Cheap, cacheable and deployable anywhere.
- Hobby project, personal site or you want to learn: Docker on a VPS with Caddy in front. Around $5/month.
- Professional project that should scale without managing servers: a container platform like Fly.io or Google Cloud Run, plus a shared cache handler.
- You want Vercel-like infrastructure on your own AWS account: SST with OpenNext.
Whatever you choose: Next.js is not locked to Vercel. You just have to know which trade-offs you are making. 🙌
Footnotes
-
Deploy the same app to different targets like AWS ECS, Lambda, etc. ↩
-
A Docker container can be deployed to a serverless environment, but not all Next.js features will work as expected. ↩
-
Opt-in feature. ↩
-
No out-of-the-box functionality, needs additional configuration. ↩
-
Uses a “fake” edge runtime running inside the container. ↩
-
You have to use a custom image loader or leave images unoptimized. ↩
-
Only
GETrequests are supported. They run at build time and their payloads turn into static files. ↩ -
Only supported when using
generateStaticParams. ↩