Koskamo

Next.js self-hosting behind a reverse proxy

Document v1 · Koskamo editorial · recorded 2026-09-21

Original source

When self-hosting Next.js with next start, put a reverse proxy such as nginx in front of the Node server instead of exposing it directly. The proxy handles malformed requests, slow-connection attacks, payload size limits, and rate limiting so the Next.js server spends its resources on rendering. Proxy (the renamed middleware) works self-hosted with no extra configuration under next start. Caching and ISR work automatically for a single instance with persistent local disk; multiple instances need shared cache coordination, a consistent build ID or deploymentId, and the same NEXT_SERVER_ACTIONS_ENCRYPTION_KEY on every instance. Scope: Next.js 16. Reviewed September 21, 2026.