Note: You are viewing the new Next.js documentation. The old docs are still available here.

Deployment

ZEIT Now (Recommended) permalink

The easiest way to deploy Next.js to production is to use the ZEIT Now platform from the creators of Next.js. ZEIT Now is an all-in-one platform with Global CDN supporting static & JAMstack deployment and Serverless Functions.

Getting started permalink

If you haven’t already done so, push your Next.js app to a Git provider of your choice: GitHub, GitLab, or BitBucket. Your repository can be private or public.

Then, follow these steps:

  1. Sign up to ZEIT Now (no credit card is required).
  2. After signing up, you’ll arrive on the “Import Project” page. Under “From Git Repository”, choose the Git provider you use and set up an integration. (Instructions: GitHub / GitLab / BitBucket).
  3. Once that’s set up, click “Import Project From …” and import your Next.js app. It auto-detects that your app is using Next.js and sets up the build configuration for you. No need to change anything — everything just works!
  4. After importing, it’ll deploy your Next.js app and provide you with a deployment URL. Click “Visit” to see your app in production.

Congratulations! You’ve just deployed your Next.js app! If you have questions, take a look at the ZEIT Now documentation.

If you’re using a custom server, we strongly recommend migrating away from it (for example, by using dynamic routing). If you cannot migrate, consider other hosting options.

DPS: Develop, Preview, Ship permalink

Let’s talk about the workflow we recommend using. ZEIT Now supports what we call the DPS workflow: Develop, Preview, and Ship:

  • Develop: Write code in Next.js. Keep the development server running and take advantage of its hot code reloading feature.
  • Preview: Every time you push changes to a branch on GitHub / GitLab / BitBucket, ZEIT Now automatically creates a new deployment with a unique URL. You can view them on GitHub when you open a pull request, or under “Preview Deployments” on your project page on ZEIT Now. Learn more about it here.
  • Ship: When you’re ready to ship, merge the pull request to your default branch (e.g. master). ZEIT Now will automatically create a production deployment.

By using the DPS workflow, in addition to doing code reviews, you can do deployment previews. Each deployment creates a unique URL that can be shared or used for integration tests.

Optimized for Next.js permalink

ZEIT Now is made by the creators of Next.js and has first-class support for Next.js.

For example, the hybrid pages approach is fully supported out of the box.

Custom Domains, Environment Variables, Automatic HTTPS, and more permalink

  • Custom Domains: Once deployed on ZEIT Now, you can assign a custom domain to your Next.js app. Take a look at our documentation here.
  • Environment Variables: You can also set environment variables on ZEIT Now. Take a look at our documentation here. You can then use those environment variables in your Next.js app.
  • Automatic HTTPS: HTTPS is enabled by default (including custom domains) and doesn't require extra configuration. We auto-renew SSL certificates.
  • More: Read our documentation to learn more about the ZEIT Now platform.

Other hosting options permalink

Node.js Server permalink

Next.js can be deployed to any hosting provider that supports Node.js. This is the approach you should take if you’re using a custom server.

Make sure your package.json has the "build" and "start" scripts:

{
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start"
  }
}

next build builds the production application in the .next folder. After building, next start starts a Node.js server that supports hybrid pages, serving both statically generated and server-side rendered pages.

Static HTML Export permalink

If you’d like to do a static HTML export of your Next.js app, follow the directions on our documentation. By default, next export will generate an out directory, which can be served by any static hosting service or CDN.

We strongly recommend using ZEIT Now even if your Next.js app is fully static. ZEIT Now is optimized to make static Next.js apps blazingly fast. next export works with Zero Config deployments on ZEIT Now.