Next.js
Neatploy runs Next.js as a normal long-lived Node server in a container. Server Components, Server Actions, middleware, streaming, ISR and next/image work as they do with next start on your own machine. No serverless time limits apply, and WebSockets and background work keep running.
How your app is built
When your repository has no Dockerfile, Neatploy builds it with Railpack:
- installs dependencies with your package manager (npm, pnpm, Yarn or Bun)
- runs your
buildscript - starts the app with your
startscript, usuallynext start - keeps
.next/cachebetween builds keyed per service and environment, so rebuilds are faster
If your next.config sets output: "export", the static files are served directly and no Node server runs.
With a Dockerfile, your Dockerfile decides everything. Neatploy’s build log adds hints for common Next.js issues and checks the detected next version against known security advisories (via osv.dev) without failing the build.
Edge security and runtime defaults
At the edge, Neatploy strips internal Next.js headers such as x-middleware-subrequest from incoming external requests before they reach your application (protecting against middleware-bypass vulnerabilities like CVE-2025-29927) and enables gzip/zstd compression automatically.
When the last build detected Next.js, Neatploy sets these runtime variables unless you define them yourself:
| Variable | Value | Why |
|---|---|---|
PORT | the service port | next start and server.js listen on it |
HOSTNAME | 0.0.0.0 | the standalone server.js listens on HOSTNAME, which Docker otherwise sets to the container ID |
NEXT_TELEMETRY_DISABLED | 1 | no telemetry from your production servers |
Smaller images with output: "standalone"
Railpack copies node_modules into the image and runs your start script, so output: "standalone" doesn’t shrink Railpack images. To get a smaller image, add a Dockerfile that copies .next/standalone, .next/static and public into a slim Node image and runs node server.js. Next.js publishes an example Dockerfile.
Images
Next.js 15 and later install sharp for next/image themselves. On Next.js 13 and 14, add sharp to dependencies. Without it, image optimization is slow and uses significant memory.
More than one replica: share the cache
Each replica keeps its own ISR and data cache on its own disk. With two or more replicas, a page revalidated on one replica stays stale on the others, so visitors can see different versions. The build log warns about this.
To share the cache across replicas:
- Add a managed Redis service in the same environment, and give your app its connection URL as
REDIS_URL. - Add a cache handler that stores entries in Redis. Start from the Next.js Redis cache handler example, or use one of the production handlers listed in its README.
- Point Next.js at it and turn off the in-memory cache:
module.exports = {
cacheHandler: require.resolve("./cache-handler.js"),
cacheMaxMemorySize: 0,
};
If you use 'use cache' directives, configure cacheHandlers too. On the App Router with several replicas, the handler should also implement refreshTags() so every replica learns about revalidateTag calls.
A cache stored in Redis outlives a redeploy. Prefix key names with NEATPLOY_DEPLOYMENT_ID so a new deployment does not serve pages rendered by an older build. With a single replica, the cache lives in the container and resets on every deploy.
All replicas of a deployment run the same image, so they share the build ID and the Server Actions encryption key without needing NEXT_SERVER_ACTIONS_ENCRYPTION_KEY.