Skip to content

Command Palette

Search for a command to run...

How to Deploy Next.js to a VPS

Updated Jun 2026

A battle-tested, step-by-step guide to deploying a production Next.js app to your own VPS with Docker, Nginx, and zero-downtime restarts.

Before you start
  • A VPS with 2 vCPU / 2 GB RAM — Next.js builds are memory-hungry.
  • Node.js 20+ (and a process manager like PM2), or Docker, on the server.
  • A domain pointed at the server if you want HTTPS.
  • Your app in a Git repo you can clone onto the box.

Vercel is great until the bill scales with traffic. Running the same Next.js app on a $5 VPS gives you predictable cost and full control. Here is the exact setup I run in production.

What you need

  • A VPS with at least 2 GB RAM (Next.js builds are memory-hungry).
  • Docker and Docker Compose.
  • A domain pointed at the server.

1. Dockerfile

Use the standalone output to keep the image small:

// next.config.mjs
export default { output: "standalone" };
FROM node:22-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:22-alpine AS build
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
FROM node:22-alpine AS run
WORKDIR /app
COPY --from=build /app/.next/standalone ./
COPY --from=build /app/.next/static ./.next/static
COPY --from=build /app/public ./public
EXPOSE 3000
CMD ["node", "server.js"]

2. Compose + Nginx

A minimal docker-compose.yml plus an Nginx reverse proxy for TLS termination gets you HTTPS in a few minutes. (Full config in the repo.)

3. Pick the right VPS

A 2 vCPU / 4 GB box handles a Next.js app plus a small database comfortably. See Best VPS for Node.js & Next.js Apps for the ranked picks.

Next steps