Black Friday: 40% off for life · BLACKFRIDAY40Claim →
crabsmith Get started
Browse documentation
← All documentation

Next.js

On this page

Deploy a Next.js app behind Caddy with automatic HTTPS. Each deploy builds your app and restarts next start as a managed daemon.

Required services

On your server's Services tab, install Caddy and Node.js (24 by default). Add pnpm if your project uses it.

Create the site

  1. Open your server's Sites tab, click New site, and choose Next.js.
  2. Follow the App → Code → Domain → Run steps: pick your repository and branch, enter your domain (or Free domain), and review the Run step.
  3. On Run, Run the app as a daemon is enabled by default (npm run start -- -p <port>), and Crabsmith adds its restart command to your deploy script automatically.
  4. If your build needs NEXT_PUBLIC_* or other build-time variables in .env.production before the first build, uncheck Deploy after creating—otherwise leave it checked—and click Create site.

The default deploy script builds your app and restarts the daemon (commit package-lock.json so npm ci works reliably):

sh
npm ci
npm run build
sudo systemctl try-restart crabsmith-daemon-<id>

Using pnpm? Update Settings → Deployment to pnpm install --frozen-lockfile && pnpm run build (keeping the restart line), and update the daemon command under Processes to pnpm run start -- -p <port>.

Note

next build is memory-intensive. A 1 GB server uses swap and can take several minutes—a 2 GB+ server is recommended for faster, smoother builds.

Environment variables and deploying

If you deferred the first deploy, open the site's Environment tab (.env.production), add your build-time and runtime variables, click Save, and then click Deploy now.

Verify

Open your site in a browser. Check the running daemon and its logs anytime under Processes. (If you turned off Run the app as a daemon during setup, create a daemon there with npm run start -- -p <your-site-port> and paste its restart line into Settings → Deployment.)