---
title: "How do I self-host a Next.js app without Vercel?"
description: "Run next build and next start on any Node.js server, or use output: standalone for a small Docker image. Caching, multiple instances and streaming need a little extra setup."
url: https://www.danny.engineering/answer/nextjs/how-do-i-self-host-a-nextjs-app-without-vercel
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["Next.js"]
---

# How do I self-host a Next.js app without Vercel?

## The short answer


Next.js runs on any server with Node.js. Build it, then start the built-in server. Next.js 16 needs Node.js 20.9 or later, but Node 20 is past end of life, so use Node 24 or 26.


```bash
npm ci
npm run build   # next build
npm run start   # next start, listens on port 3000
```


For containers, set `output: 'standalone'` in `next.config.ts`. The build then produces a small folder you can copy into a Docker image without installing `node_modules`.


## Why it happens


People often assume Next.js needs Vercel because some features feel tied to the platform. They are not. Server Components, Route Handlers, Server Actions, `proxy.ts`, image optimisation, ISR and Cache Components all work with `next start`.


What Vercel adds is infrastructure around the app: a CDN, a shared cache across many instances, and coordination between deployments. When you host it yourself, a single server with a persistent disk works out of the box. Running several instances, or putting a proxy in front, is where you need extra setup.


## How to fix it


### Build a standalone Docker image


Enable standalone output:


```typescript
// next.config.ts
import type { NextConfig } from 'next';

const nextConfig: NextConfig = {
  output: 'standalone',
};

export default nextConfig;
```


`next build` now writes `.next/standalone`, which contains a minimal `server.js` and only the dependencies your code uses. It does not include `public` or `.next/static`, because those are meant for a CDN, so copy them in yourself. A multi-stage Dockerfile:


```bash
# Dockerfile
FROM node:24-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci

FROM node:24-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build

FROM node:24-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME=0.0.0.0
RUN addgroup -S nodejs && adduser -S nextjs -G nodejs
COPY --from=builder /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]
```


Add a `.dockerignore` with `node_modules`, `.next`, `.git` and your `.env*` files, so secrets stay out of the image. `HOSTNAME=0.0.0.0` matters: without it the server may only listen inside the container and you cannot reach it.


### Put a reverse proxy in front


The Next.js docs recommend nginx, Caddy or a similar proxy rather than exposing Node directly. It handles TLS, slow clients, payload limits and rate limiting. If you use streaming, `loading.tsx` or Suspense, turn off response buffering, or users see nothing until the whole page is ready. For nginx, you can send `X-Accel-Buffering: no` from Next.js:


```typescript
// next.config.ts
const nextConfig: NextConfig = {
  output: 'standalone',
  async headers() {
    return [{ source: '/:path*', headers: [{ key: 'X-Accel-Buffering', value: 'no' }] }];
  },
};
```


### Handle environment variables


Server-only variables are read at runtime, so one image can move between staging and production. `NEXT_PUBLIC_` variables are different: they are written into the browser bundle during `next build`. Changing them means rebuilding the image.


### Extra setup for more than one instance


If you run several containers behind a load balancer:

- **Shared cache.** ISR pages and cached data are stored on each instance's disk and in memory. Point `cacheHandler` (and `cacheHandlers` for `'use cache'`) at shared storage such as Redis, so a revalidation on one instance applies to all.
- **Server Actions key.** Set the same `NEXT_SERVER_ACTIONS_ENCRYPTION_KEY` at build time for every instance, or you will see "Failed to find Server Action" errors.
- **Version skew.** Set `deploymentId` in `next.config` during rolling deploys, so clients on an old version do a full reload instead of requesting files that no longer exist.
- **Same build everywhere.** Build once and ship the same image to every instance. If you must rebuild per environment, use `generateBuildId` to keep the ID consistent.

### Shut down cleanly


Send `SIGTERM` or `SIGINT` and give the process 10 to 30 seconds. Next.js finishes in-flight requests and any pending `after()` callbacks before it exits.


## Common pitfalls

- **Missing CSS and images.** If the page loads unstyled, you forgot to copy `.next/static` and `public` into the standalone folder.
- **Running next dev in production.** Dev mode is slow and not secure. Always run a production build.
- **Image optimisation memory.** On glibc-based Linux, the `sharp` library behind `next/image` may need a different memory allocator to avoid high memory use. See the sharp install docs.
- **Expecting static export to cover everything.** `output: 'export'` produces plain HTML, but drops proxy, Server Actions, ISR and default image optimisation.
- **Monorepo files left out.** Set `outputFileTracingRoot` to the repo root so shared packages are traced into the standalone output.

## Related reading

- [Next.js: Self-hosting guide](https://nextjs.org/docs/app/guides/self-hosting)
- [Next.js: output config](https://nextjs.org/docs/app/api-reference/config/next-config-js/output)
- [Next.js: Deploying](https://nextjs.org/docs/app/getting-started/deploying)
