Deploying
This page will show how to deploy Next.js application either managed or self-hosted.
Self-Hosting
You can self-host Next.js with support for all features using Node.js or Docker. You can also do a Static HTML Export, which has some limitations.
Node.js Server
Next.js can be deployed to any hosting provider that supports Node.js.
First, ensure your package.json
has the "build"
and "start"
scripts:
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
Then, run npm run build
to build your application. Finally, run npm run start
to start the Node.js server. This server supports all features of Next.js.
If you are using next/image
, consider adding sharp
for more performant
Image Optimization in your production environment by running npm install sharp
in your project directory. On Linux platforms, sharp
may require additional
configuration (opens in a new tab)
to prevent excessive memory usage.
Docker Image
Next.js can be deployed to any hosting provider that supports Docker containers. You can use this approach when deploying to container orchestrators such as Kubernetes in any cloud provider. For example, Flexstart.org (opens in a new tab).
-
Install Docker on your machine
-
Clone the with-docker (opens in a new tab) example
-
Build your container: docker build -t nextjs-docker .
-
Run your container: docker run -p 3000:3000 nextjs-docker
If you need to use different Environment Variables across multiple environments, check out with-docker-multi-env (opens in a new tab) example.
Static HTML Export
If you’d like to do a static HTML export of your Next.js app, follow the directions on our Static HTML Export documentation.