A Next.js Pages Router application can be deployed to any Node.js environment, containerized with Docker, or exported as static HTML.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/next.js/llms.txt
Use this file to discover all available pages before exploring further.
Deploying to Vercel
Vercel is the platform built by the Next.js team. It requires zero configuration.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.
- 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: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 aDockerfile at the root of your project:
Dockerfile
next.config.js so Next.js produces a self-contained server.js file:
next.config.js
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. Setoutput: 'export' in next.config.js:
next.config.js
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 withoutput: '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
Serving the export
To serve theout/ 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 setCache-Control headers in getServerSideProps:
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.
