NextDeploy VPS Deployment Guide: Zero-Downtime Linux Releases Grounded in Go
Deploy Next.js apps to any VPS with zero downtime, automatic SSL, and a daemon-managed release pipeline. No containers, no Kubernetes, no cloud lock-in — just SSH, systemd, and Caddy.
Deploy Next.js apps to any VPS with zero downtime, automatic SSL, and a daemon-managed release pipeline. No containers, no Kubernetes, no cloud lock-in — just SSH, systemd, and Caddy.
This document is the source of truth for VPS deployment infrastructure, grounded in the actual implementation. It focuses on what you do and what happens under the hood.
No containers, no Kubernetes, no cloud lock-in — just SSH, systemd, and Caddy driven by a dual-binary architecture.
curl -fsSL https://hersi.dev/install.sh | bash (macOS/Linux) or irm https://hersi.dev/install.ps1 | iex (Windows). For architecture details, manual binaries, and setup verification, see the What is NextDeploy? Complete Installation Guide.Architecture at a Glance
Architecture:Two binaries, two roles:
Communication: The CLI SSHes into the server and runs sudo nextdeployd ship --tarball=<path>. The daemon subcommand is itself a socket client — it dials the running daemon, HMAC-signs the command, and sends it. The daemon verifies the signature, checks for replays, rate-limits, and dispatches.
Quick Start
1# 1. In your Next.js project:
2nextdeploy init # generates nextdeploy.yml
3
4# 2. Edit nextdeploy.yml — set your server IP, SSH key, and domain
5
6# 3. Provision the server (installs Node, Caddy, daemon, hardening):
7nextdeploy prepare
8
9# 4. Point your domain's A record at the server IP
10
11# 5. Build and deploy:
12nextdeploy ship
13
14# 6. Check on it:
15nextdeploy status
16nextdeploy logs1. Initialize a Project (nextdeploy init)
What it does:
What it does NOT do:
The generated nextdeploy.yml (VPS template):
1target_type: vps
2
3app:
4 name: example-app # slug, NOT a domain
5 environment: production
6 domain: app.example.com # your public domain
7 port: 3000 # internal port the app listens on
8
9 gosidecar:
10 enabled: false
11 image_optimization: true
12 isr_cache: true
13 max_image_workers: 4
14
15servers:
16 - name: "production-01"
17 host: 1.2.3.4
18 username: ubuntu
19 key_path: ~/.ssh/id_rsaThe template also includes commented-out blocks for logging, monitoring, backup, and webhooks. See Configuration Reference below for the full schema.
Key fields to set before your first deploy:
| Field | Purpose |
|---|---|
| app.name | The app identifier — used for the systemd unit name, app directory, and Caddy fragment filename. Must be a slug. |
| app.domain | The public domain Caddy will serve. Can be a bare hostname or a block with DNS provider info. |
| app.port | The internal port your Node process listens on. Caddy proxies to this. Default: 3000. |
| servers[].host | IP or hostname of your VPS. |
| servers[].username | SSH user (must have passwordless sudo). |
| servers[].key_path | Path to your SSH private key. |
2. Prepare the Server (nextdeploy prepare)
Provisions a fresh Linux VPS end-to-end. Every step checks before it changes, so re-running converges instead of redoing work.
Default mode is "agent mode" — no Ansible, no Python on the target. The CLI SSHes to the server, downloads the latest nextdeployd binary from GitHub releases, installs it, and runs nextdeployd prepare on the server. The target needs only a shell and curl (or wget).
Provisioning steps (in dependency order):
| Step | What it installs/creates |
|---|---|
| Base packages | curl, tar, ca-certificates, unzip (via apt/dnf/yum — auto-detected) |
| Service user | nextdeploy system group + user (shell: /sbin/nologin, no home) |
| Directory tree | /opt/nextdeploy/{apps,uploads,tmp} (0750, owned nextdeploy:nextdeploy) |
| Node.js 22 | Via NodeSource signed repo (pinned major). Symlinked to /usr/local/bin. |
| Corepack | corepack enable + pnpm@latest + yarn@stable. Symlinked to /usr/local/bin. |
| Doppler CLI | Optional — fetched from cli.doppler.com/install.sh. Failure is non-fatal. |
| Caddy | Via Cloudsmith apt repo or COPR (rpm), with a static-binary fallback. caddy user added to nextdeploy group for directory traversal. |
| Coraza WAF | Caddy binary replaced with one compiled with the Coraza WAF module (coraza-caddy/v2). |
| Main Caddyfile | Seeded at /etc/caddy/Caddyfile with order coraza_waf first + import /etc/caddy/nextdeploy.d/*.caddy. |
| Daemon config | /etc/nextdeployd/config.json with a random 32-byte HMAC secret (0600). |
| Daemon unit | nextdeployd.service — runs nextdeployd --foreground=true as root, ordered After=network.target caddy.service, with RuntimeDirectory=nextdeployd. |
| Daemon socket | /run/nextdeployd/nextdeployd.sock (0660, root:nextdeploy) — the whole local authorization model. |
| Hardening | fail2ban with two jails: caddy-auth (repeated 401/403 in Caddy access log) and caddy-waf (Coraza interventions in audit log). Plus logrotate for /var/log/caddy/*.log. |
Flags:
1nextdeploy prepare # default: agent mode, first configured server
2nextdeploy prepare --all # prepare every configured server
3nextdeploy prepare --server prod-02 # prepare a specific server by name
4nextdeploy prepare --skip-runtimes # skip Node/Corepack (host manages runtimes)
5nextdeploy prepare --skip-hardening # skip fail2ban + logrotate
6nextdeploy prepare --allow-root # allow provisioning over root SSH (not recommended)
7nextdeploy prepare --ansible # legacy Ansible playbook (needs ansible-playbook + python3)
8nextdeploy prepare --timeout 15m # overall timeout (default: 10m)Requirements:
3. Build (nextdeploy build)
Builds the Next.js app and packages it into app.tar.gz — the artifact the daemon deploys.
The build flow (buildflow.Run):
1nextdeploy build # build + package
2nextdeploy build --force # force a full rebuild even if inputs are unchanged4. Ship (nextdeploy ship)
Builds (if needed), uploads, and triggers the daemon to deploy. This is the command you run.
Step by step, from the CLI:
Flags:
1nextdeploy ship # build + upload + deploy
2nextdeploy ship --force # force a full rebuild first
3nextdeploy ship -e staging # deploy to a named environment
4nextdeploy ship -v # verbose deployment logsZero-Downtime Deployment: How It Works
This is the core of the system. The new release is started and health-checked on its own port BEFORE the current symlink and Caddy routing move. A failed deploy never leaves the server serving a broken release.
Step 1: Extract & validate
Step 2: Port allocation
Step 3: Render secrets
Step 4: Generate systemd unit
Step 5: Start & health check
Step 6: Sync static assets
Step 7: Go sidecar (optional)
Step 8: Caddy fragment
Step 9: Atomic symlink flip (THE zero-downtime switch)
Step 10: Cleanup
Rollback on failure
A defer watches activationCommitted. If any step after a commit point fails, it restores the previous current symlink, restores the old Caddy fragment + reloads Caddy, stops the candidate sidecar, removes the candidate service, and restores the port state.
5. Status (nextdeploy status)
Queries the daemon for the active service state:
nextdeploy status6. Logs (nextdeploy logs)
Streams logs from the server. All over SSH — no log shipping agent needed.
1nextdeploy logs # app logs (journalctl -u <service> -f -n 50)
2nextdeploy logs --route /api # filter by route pattern (grep)
3nextdeploy logs --audit # daemon audit log (who ran what command)
4nextdeploy logs --daemon # daemon system log
5nextdeploy logs --all # all three streams simultaneouslyLog locations on the server:
| Log | Path | Content |
|---|---|---|
| App | journalctl -u nextdeploy-<app>-<releaseID> | Next.js application output |
| Daemon | /var/log/nextdeployd/nextdeployd.log | Daemon lifecycle events |
| Audit | /var/log/nextdeployd/audit.log | Every command: type, who ran it, success/failure |
| Caddy access | /var/log/caddy/access.log | HTTP access (JSON format) |
| Caddy WAF | /var/log/caddy/audit.log | Coraza WAF interventions |
| Caddy debug | /var/log/caddy/debug.log | Coraza rule evaluation (level 1) |
7. Rollback (nextdeploy rollback)
Reverts to a previous release. Uses the same activateRelease flow as a fresh ship — health check, Caddy, symlink flip, cleanup.
1nextdeploy rollback # roll back one step (the previous release)
2nextdeploy rollback --steps 3 # roll back 3 steps (max 5, the retention limit)
3nextdeploy rollback --to 7c8350a # roll back to a specific git commit (full or short SHA)How it works:
8. Secrets (nextdeploy secrets)
Manage environment variables for your deployed app. VPS secrets are stored on the server at /opt/nextdeploy/secrets/<app>.json (0600, root only).
1nextdeploy secrets set DATABASE_URL=postgres://... # set one or more
2nextdeploy secrets set API_KEY=xxx STRIPE_KEY=yyy # set multiple at once
3nextdeploy secrets get DATABASE_URL # get a value (plaintext)
4nextdeploy secrets list # list all secret names
5nextdeploy secrets unset DATABASE_URL # remove one or more
6nextdeploy secrets load # load from .env file
7nextdeploy secrets load .env.production # load from a specific file9. Destroy (nextdeploy destroy)
Permanently removes the app and all its resources from the server. Destructive and guarded.
1nextdeploy destroy # interactive: type the app name to confirm
2nextdeploy destroy --force # override deletion_protection
3nextdeploy destroy --yes # skip the confirmation prompt
4nextdeploy destroy -e staging # destroy a specific environmentWhat it removes:
Guards:
Environments
Deploy isolated stacks of the same app using --environment / -e:
1nextdeploy ship -e staging
2nextdeploy ship -e pr-42
3nextdeploy destroy -e stagingGo Sidecar
An optional Go binary that runs alongside your Node.js app to serve eligible prerendered pages and image requests without waking the Node process.
1app:
2 gosidecar:
3 enabled: true
4 image_optimization: true # serve optimized images (default: true)
5 isr_cache: true # cache ISR pages (default: true)
6 max_image_workers: 4 # concurrent image workers (default: 4, max: 64)Resource Limits
Opt-in cgroup throttling for VPS deploys, mapped to systemd directives in the generated unit file:
1app:
2 resources:
3 cpu_quota: "80%" # percentage (may exceed 100% on multi-core)
4 memory_max: "1G" # hard cap — OOM-killed past this
5 memory_high: "800M" # soft throttle — reclaim pressure, not a killValues are validated against systemd's resource-control grammar before they reach the unit file (cpu_quota: ^[1-9][0-9]*%$, memory_max / memory_high: ^[0-9]+(\.[0-9]+)?([KMGT])?$), preventing a hostile or fat-fingered config from injecting arbitrary unit directives.
SSL / TLS
SSL is automatic via Caddy's built-in Let's Encrypt integration. No manual certificate handling.
DNS-01 challenges (wildcard certs): Configure the ssl_config or ssl block in nextdeploy.yml with a DNS provider and email:
1ssl_config:
2 domain: "*.example.com"
3 email: ops@example.com
4 dns_provider: cloudflare
5 wildcard: true
6 staging: false # use Let's Encrypt staging for testingSecurity Model
Daemon command authentication
Every command sent to the daemon is HMAC-SHA256 signed:
Socket permissions
systemd unit hardening
Every app service runs with:
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
NoNewPrivileges=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
LockPersonality=yes
ReadWritePaths=<releaseDir>
KillMode=control-group
TimeoutStopSec=10s
FinalKillSignal=SIGKILL
OOMPolicy=stopEdge security (Caddy) & Path sanitization
Server Filesystem Layout
/opt/nextdeploy/
├── apps/
│ └── <app-name>/
│ ├── releases/
│ │ ├── 1730798400-7c8350a/ # immutable release directory
│ │ ├── 1730802000-a1b2c3d/
│ │ └── ... # up to 5 retained (pruned automatically)
│ ├── current -> releases/<id> # atomic symlink — THE active release
│ ├── shared_static/ # synced .next/static (survives cutover)
│ └── port # the port the active service is on
├── uploads/
│ └── nextdeploy_<app>_<timestamp>.tar.gz # uploaded tarballs (deleted after deploy)
├── tmp/ # unpack workspace
└── secrets/
└── <app>.json # secret store (0600, root only)
/etc/nextdeployd/
└── config.json # daemon config + HMAC secret (0600)
/etc/caddy/
├── Caddyfile # main config (imports fragments)
└── nextdeploy.d/
└── <app>.caddy # per-app fragment (generated on deploy)
/etc/systemd/system/
├── nextdeployd.service # the daemon
└── nextdeploy-<app>-<releaseID>.service # app services (one per active release)
/run/nextdeployd/
└── nextdeployd.sock # Unix socket (0660, root:nextdeploy)
/var/log/nextdeployd/
├── nextdeployd.log # daemon system log
└── audit.log # command audit log
/var/log/caddy/
├── access.log # HTTP access (JSON)
├── audit.log # Coraza WAF interventions
└── debug.log # Coraza debug (level 1)
/usr/local/bin/
├── nextdeployd # the daemon binary
├── node # Node.js 22
├── npm / npx / pnpm / yarn # package managers (via Corepack)
├── caddy # Caddy with Coraza WAF module
└── doppler # Doppler CLI (optional)Configuration Reference
The full nextdeploy.yml schema for VPS deployments. Only app and servers are required; everything else is opt-in.
Core fields
1version: "1.0"
2target_type: vps
3
4app:
5 name: example-app # REQUIRED — slug (^[a-z0-9-]+$), 3-63 chars
6 environment: production # REQUIRED — production | staging | development
7 domain: app.example.com # public domain (bare hostname or block)
8 port: 3000 # REQUIRED — internal app port
9
10 # Domain as a block (optional — for DNS guidance):
11 # domain:
12 # name: app.example.com
13 # provider: cloudflare # namecheap | cloudflare | other
14 # dns: auto # auto (provider API) | manual (print records)
15 # zone: example.com
16
17 deletion_protection: true # guards `destroy` (default: false)
18
19 gosidecar: # optional Go sidecar
20 enabled: false
21 image_optimization: true
22 isr_cache: true
23 max_image_workers: 4
24
25 resources: # optional cgroup limits
26 cpu_quota: "80%"
27 memory_max: "1G"
28 memory_high: "800M"
29
30servers:
31 - name: "production-01" # REQUIRED — friendly name
32 host: 1.2.3.4 # REQUIRED — IP or hostname
33 username: ubuntu # REQUIRED — SSH user (needs passwordless sudo)
34 key_path: ~/.ssh/id_rsa # path to SSH private key
35 # password: "" # optional (key_path takes precedence)
36 # port: 22 # optional SSH portOptional blocks (SSL, Logging, Monitoring, Backup, Webhooks)
1ssl_config:
2 domain: "*.example.com"
3 email: ops@example.com
4 dns_provider: cloudflare # for DNS-01 challenges
5 wildcard: true
6 staging: false # use Let's Encrypt staging for testing
7 force: false # force re-issuance
8
9# Legacy ssl block (still supported):
10ssl:
11 enabled: true
12 provider: letsencrypt
13 email: ops@example.com
14 auto_renew: true
15
16logging:
17 enabled: true
18 provider: nextdeploy
19 stream_logs: true
20 log_path: /var/log/containers/example-app.log
21
22monitoring:
23 enabled: true
24 cpu_threshold: 80
25 memory_threshold: 75
26 disk_threshold: 90
27 alert:
28 email: ops@example.com
29 slack_webhook: https://hooks.slack.com/services/...
30 notify_on: [crash, healthcheck_failed, high_cpu, high_memory]
31
32backup:
33 enabled: true
34 frequency: daily # hourly | daily | weekly
35 retention_days: 7
36 storage:
37 provider: s3
38 bucket: nextdeploy-backups
39 region: us-east-1
40
41webhook:
42 on_success:
43 - curl -X POST https://your-api.com/deploy/success
44 on_failure:
45 - curl -X POST https://your-api.com/deploy/failureCommand Quick Reference
| Command | What it does |
|---|---|
| nextdeploy init | Scaffold nextdeploy.yml for your project |
| nextdeploy prepare | Provision a VPS (Node, Caddy, daemon, hardening) |
| nextdeploy build | Build + package app.tar.gz |
| nextdeploy build --force | Force a full rebuild |
| nextdeploy ship | Build + upload + deploy to VPS |
| nextdeploy ship --force | Force rebuild then deploy |
| nextdeploy ship -e <env> | Deploy to a named environment |
| nextdeploy status | Show active service state (PID, memory, status) |
| nextdeploy logs | Stream app logs |
| nextdeploy logs --route /api | Filter logs by route |
| nextdeploy logs --all | Stream app + audit + daemon logs |
| nextdeploy rollback | Roll back one step |
| nextdeploy rollback --steps 3 | Roll back 3 steps |
| nextdeploy rollback --to <sha> | Roll back to a specific commit |
| nextdeploy secrets set K=V | Set secrets (hot-reloads the active service) |
| nextdeploy secrets list | List secret names |
| nextdeploy secrets get K | Get a secret value |
| nextdeploy secrets unset K | Remove secrets |
| nextdeploy secrets load | Load from .env file |
| nextdeploy destroy | Remove app + resources (guarded) |
| nextdeploy destroy --force | Override deletion_protection |
| nextdeploy inspect | Read-only bundle size audit |
Infrastructure simplicity is developer independence. True zero downtime requires disciplined, release-pinned state orchestration.