Skip to main content
A Next.js Pages Router application can be deployed to any Node.js environment, containerized with Docker, or exported as static HTML.

Deploying to Vercel

Vercel is the platform built by the Next.js team. It requires zero configuration.
1

Push your code to a Git provider

Push your repository to GitHub, GitLab, or Bitbucket.
2

Import your repository on Vercel

Go to vercel.com/new, import your repository, and click Deploy. Vercel detects that you are using Next.js automatically.
3

Set environment variables

In your Vercel project settings, add any environment variables from your .env.local that are needed in production.
Vercel automatically handles:
  • Building and deploying on every push.
  • Serverless Functions for API routes and SSR pages.
  • Incremental Static Regeneration on the edge.
  • Image optimization.
  • Preview deployments for pull requests.

Deploying to a Node.js server

For a self-hosted Node.js deployment:
1

Build the application

This generates optimized production assets in the .next/ directory.
2

Start the production server

By default, the server listens on port 3000. Set the PORT environment variable to change it:

Keeping the server running

Use a process manager like PM2 to keep your server running and restart it on crash:

Deploying with Docker

Docker lets you package your application with its dependencies and deploy it anywhere containers run. Create a Dockerfile at the root of your project:
Dockerfile
Enable standalone output in next.config.js so Next.js produces a self-contained server.js file:
next.config.js
Build and run the container:

Static export

If your application has no server-side requirements, you can export it as static HTML files. Static exports work without a Node.js server. Set output: 'export' in next.config.js:
next.config.js
Then build:
Next.js generates a static out/ directory that you can deploy to any static hosting service (Nginx, Apache, S3, GitHub Pages, Cloudflare Pages, etc.).

Limitations of static export

The following features are not compatible with output: 'export' because they require a server:
  • getServerSideProps
  • API routes (pages/api/)
  • Image Optimization (unless you use a custom image loader)
  • Incremental Static Regeneration
  • Internationalized routing
If your app uses getServerSideProps or API routes, you cannot use static export. Use a Node.js server or Docker deployment instead.

Serving the export

To serve the out/ directory locally with Nginx:

Configuring for production

Environment variables

Set production environment variables on your hosting platform. Never commit .env.local to version control.

Caching

Next.js includes an HTTP response cache. For SSR pages, you can set Cache-Control headers in getServerSideProps:
For static pages and assets, Next.js sets immutable cache headers automatically.

Health checks

Create a health check endpoint for load balancers:
pages/api/health.ts
For a full production deployment checklist, see the Next.js production checklist.