h_HIRAX.

HIRAX / FIELD GUIDE

Next.js beyond localhost.

Build and run a Next.js application on a VPS with standalone output, a reverse proxy and explicit environment handling.

STEP 01Separate development from production

This recipe assumes a current Next.js app, an npm lockfile and Node.js 24 LTS support in your project. npm run dev is for development. First run the project checks and production build locally or in CI. Some routes may need environment variables or database access at build time.

EXAMPLE / ADAPT TO YOUR PROJECT
npm ci
npm run build

STEP 02Enable standalone output

Merge output: standalone into your existing Next.js configuration. Do not replace other project options. After building, Next creates a minimal server in .next/standalone. Public assets and .next/static need to be copied into that standalone directory.

EXAMPLE / ADAPT TO YOUR PROJECT
// next.config.ts — merge into existing config
const nextConfig = { output: 'standalone' };
export default nextConfig;

STEP 03Package the runtime

Use a multistage Docker build so the final image contains the built application. If your project has no public folder, create it or omit that COPY line. Add a .dockerignore that excludes .env files, node_modules, .git and .next.

EXAMPLE / ADAPT TO YOUR PROJECT
FROM node:24-bookworm-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:24-bookworm-slim AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
COPY --from=build --chown=node:node /app/.next/standalone ./
COPY --from=build --chown=node:node /app/.next/static ./.next/static
COPY --from=build --chown=node:node /app/public ./public
USER node
EXPOSE 3000
CMD ["node", "server.js"]

STEP 04Route traffic and handle state

Use the Docker Compose guide to put Caddy in front of the container. Runtime secrets belong in the runtime environment, not the Dockerfile. NEXT_PUBLIC variables are embedded at build time and are public. Uploads must persist outside the container; multi-instance caching and revalidation need additional planning.

STEP 05Test what users actually do

Check server-rendered HTML, assets, forms, authentication callbacks and image optimization. Check the logs and restart the container. Run a sample data write and verify persistence. Keep the previous image available for rollback.

COPY → YOUR AI

Take the next step to your AI.

A safe starting prompt for this guide. No secrets. Works with ChatGPT, Claude and other assistants.

Sources and technical documentation

Next.js self-hostingNode.js releases

This recipe is a pattern for the stated prerequisites. Verify project compatibility and your actual server configuration before applying it to a live service.

Ready for your own server?

Find a starting point for your project and compare real configurations at WVG.

Find my next step