Self Hosted Next.js

Before deciding on how your are going to self host your Next.js application, it is important to understand, that Next.js does not support to host your app as distributed application with any other provider than Vercel. Switch over to the platform compare page for more details on this.

Background & Context

Vercel is the company behind Next.js. And Vercel does own a very sophisticated hosting infrastructure.
Unlike other frameworks (e.g. Remix, Nuxt, etc.) the Next.js team can and does solve problems (e.g. performance related, caching, etc.) with this mentioned infrastructure by Vercel.
This is probably the reason why some developers assume Next.js can only be hosted on Vercel.

Next.js does not have a vender-lock – but the shadow is somewhat visible

To give you a better understanding of what that means, lets pick a feature of Next.js called Middleware.

An example: Middleware

Middleware is a feature by Next.js that "[...] allows you to run code before a request is completed." (read the docs).
When you do host your Next.js application on Vercel your middleware code gets executed on the edge network. There your request gets modified and then "passed on" to the following stages. This illustration by Vercel should help to understand the concept.
This is the reason why your are limited to a subset of APIs via the edge runtime when using the middleware feature.

When self hosting Next.js inside a Docker container or as a Node.js server the middleware code still gets executed, but the code runs in your Node.js environment (and not close to your users on a global network).

Wait – there is hope!

So when self hosting Next.js you will not get the same performance compared to hosting on Vercel.
The only self hosted option that comes close to the Vercel experience is OpenNext, that is currently backed by SST .
Hosted with SST your Next.js application runs as a distributed application (comparable to Vercel) based on AWS.

Your self hosted options