# Next.js self-hosting template pack

Reviewed for Next.js 16.2 on 2026-07-13. These files are an overlay for an existing npm-based Next.js application, not a complete application and not a production guarantee.

## Files

- `next.config.mjs`: enables standalone output and accepts a deployment identifier.
- `Dockerfile`: builds with Node.js 22 and runs the traced standalone server as a non-root user.
- `nginx.conf`: proxies to Next.js without buffering streamed responses.
- `hostnextjs.service`: supervises an unpacked standalone release with systemd.
- `.env.example`: documents runtime values without containing secrets.
- `release-artifact.yml`: validates the project and uploads an immutable standalone artifact in GitHub Actions.

## Use

1. Copy `next.config.mjs` into the project, or merge its fields into the existing Next.js config.
2. Run the normal test and production build locally.
3. Choose either the Docker runtime or the systemd runtime. Do not run both for one listener.
4. Replace `example.com`, paths, users, and commands with reviewed production values.
5. Put TLS termination in front of Nginx or extend the server block with the certificate automation used by your environment.
6. Exercise dynamic routes, Route Handlers, images, streaming, ISR, revalidation, graceful shutdown, logs, health checks, and rollback before traffic moves.

## Boundaries

The pack does not provision a server, create users, configure SSH, issue TLS certificates, install Docker, create backups, configure a firewall, manage DNS, or implement multi-instance cache coordination. It assumes `package-lock.json` and `npm run build` exist. Monorepos and native dependencies may need output tracing changes.

For multiple instances, review shared cache storage, tag invalidation, `NEXT_SERVER_ACTIONS_ENCRYPTION_KEY`, `deploymentId`, version skew, and load-balancer drain behavior in the current Next.js self-hosting documentation.

Source and methodology: https://hostnextjs.com/nextjs-self-hosting-template-pack/