Skip to content
COL0

How to deploy a Next.js app: Vercel, VPS or Docker

Next.js can be published in three ways. Choosing well from the start saves you weeks of frustration and unexpected bills.

Written by Victor Barrera

The three options

  • Vercel: the simplest. You connect the repository and every push is published automatically. Ideal to start and for small projects; costs can grow with traffic.
  • Your own VPS: you build with next build and run it with next start behind Nginx. Cheaper and more controllable, but you operate the server.
  • Docker: you package the app (with output: 'standalone' the image stays light) and run it on any server or container service.

The steps on a VPS, in short

  1. Prepare the server: Node.js LTS, non-root user, firewall (ports 22, 80 and 443).
  2. Clone the project, install dependencies and run npm run build.
  3. Set the environment variables before the build (public ones) and on the server (private ones).
  4. Keep the app alive with PM2 or systemd running npm run start.
  5. Nginx as a proxy to port 3000 and HTTPS with Let’s Encrypt.
  6. Automate the build and restart with GitHub Actions.

Common mistakes

  • Building on a server with little memory and the build dies halfway; build in your pipeline or add swap space.
  • Forgetting that optimized Next.js images need allowed domains configured.
  • Publishing private keys with the NEXT_PUBLIC_ prefix.
  • Not defining the site URL, so links or SEO point to localhost.

How we help

We tell you which of the three routes suits you based on your budget and traffic, and leave it running with a domain, HTTPS and automatic deploys.

Frequently asked questions

Why don't my environment variables work in production?

Variables starting with NEXT_PUBLIC_ are embedded at build time. If you change them after building, they do not update until you build again. The others are read on the server at runtime.

Can I deploy Next.js for free?

Vercel has a free plan for personal and learning projects. For commercial use or a lot of traffic, check the plan limits and compare with a fixed-price VPS.

Ready to publish your project?

Book your free 30-minute session and leave with a clear plan.

Book your free session