← All guides

Next.js deployment guide

Deploy a Next.js app to a VPS without losing a weekend

Next.jsVPS

Short answer

A live Next.js app on your domain, served behind Nginx with HTTPS and a deployment path you can repeat.

Why this matters

The build passes locally, but the server has missing env vars, a dead Node process, or Nginx pointing at the wrong port.

Walkthrough

  1. 01

    Prepare the production build

    Start by making the app build cleanly with production env vars present. Most broken deploys are not server problems, they are hidden build assumptions.

    • Run `npm run build` locally with production-like variables.
    • Confirm the app uses the correct Next.js output mode for your host.
    • Keep secrets out of git and load them from the server environment.
  2. 02

    Run Next.js as a long-lived process

    A VPS does not keep your app alive automatically. Use a process manager so deploys and restarts are predictable.

    • Install dependencies on the server with the same package manager used locally.
    • Run the app behind PM2 or another process supervisor.
    • Capture logs before adding Nginx so app errors are visible.
  3. 03

    Put Nginx and SSL in front

    Nginx handles public traffic, TLS, compression, and proxying to the private Node port.

    • Point DNS to the VPS before requesting SSL.
    • Proxy requests from port 80/443 to the Next.js process port.
    • Use Certbot or your preferred ACME client for HTTPS renewal.

Where RepoAssistant fits

Want this handled for you? RepoAssistant deploys Next.js apps to VPS with HTTPS, env vars, and handover notes.