Step-by-step guide

Deploy Next.js with PM2 and Nginx

Run Next.js behind Nginx with PM2 supervision, explicit release configuration, TLS, logs, health checks, and controlled reloads.

By HostNextJS Editorial TeamReviewed by HostNextJS Technical Review Published Updated
01Typeguide
02Last reviewed
03Update policyReview every 90 days.
At a glance

Deployment sequence

  1. STEP 01

    Build a release

    Install from the lockfile, build once, and keep the prior release available.

  2. STEP 02

    Declare the PM2 process

    Set the script, working directory, environment, memory policy, and shutdown timeout in an ecosystem file.

  3. STEP 03

    Proxy through Nginx

    Forward host and client headers, terminate TLS, and configure buffering for application behavior.

  4. STEP 04

    Reload after health

    Start the new release, verify representative routes, then reload traffic and retain rollback.

This stack is appropriate for a conventional VPS: Next.js owns application rendering, PM2 restarts and records the process, and Nginx receives public traffic. Keep each role explicit.

Declare the process

Use a PM2 ecosystem file rather than an undocumented command. Set a stable name, release cwd, script (node .next/standalone/server.js or the package start command), production environment, restart delay, memory ceiling, and a kill timeout long enough for graceful drain. Persist PM2 startup configuration after testing reboot behavior.

Put Nginx at the edge

Bind Next.js to a private interface or firewall-restricted port. Proxy requests with the original host and forwarding headers. Configure TLS, body limits, and timeouts deliberately. Disable response buffering for routes that depend on streaming; do not add a broad proxy cache without understanding Next.js cache headers and user-specific responses.

Release without editing live files

Build into versioned release directories and point a stable symlink at the active release. Verify the new process directly before switching. Use controlled reload, watch logs, and roll the symlink back if health, assets, images, or dynamic routes fail.

Methodology

How this resource was produced

This guide assigns one job to each layer: Next.js serves the app, PM2 supervises it, and Nginx controls public HTTP traffic.

Limitations
  • 01

    PM2 supervision does not replace server patching, external monitoring, backups, or capacity planning.

  • 02

    Cluster mode introduces multi-instance cache and build-consistency requirements.

Evidence

Sources and review record

Primary documentation checked for the material claims on this page. Product behavior and prices can change after the checked date.

  1. 01 · Next.jsHow to self-host Next.jsChecked July 12, 2026
  2. 02 · PM2PM2 ecosystem fileChecked July 12, 2026
  3. 03 · NGINXNGINX proxy moduleChecked July 12, 2026
Next step

Turn the resource into a deployment decision.

Review your VPS deployment