Skip to main content
Servers Are UpVirtual Datacenter
Virtual Datacenter
Pricing
Sign inBrowse plans
Servers Are UpVirtual Datacenter
Virtual Datacenter
Pricing
Sign inBrowse plans

Loading…

Servers Are UpEncrypted Multi-Provider VDC

Your Encrypted Multi-Provider Virtual Datacenter: run high-RAM Dallas Private Vault workloads ($0 Cloudflare HTTPS egress), connect AWS/Azure/GCP/on-prem free from 1 node, or expand to global Partner Edge nodes—unified over WireGuard, Browser Console, and 200-tool MCP.

Customer Portal & Services

Client DashboardMulti-Provider VDCMy ServersBYOC & HybridBrowser ConsoleBillingAPI Keys & MCPSupport
SLA with service creditsDallas Private VaultBYOC Free -> $99/mo6 Edge Regions (Soon)

Make room for your next idea

Explore the capacity, apps and access options that fit your workload. Check current availability and your total before you buy.

Sign up freeView Pricing

Products

  • Linux VPS
  • Windows VPS
  • Cloud & SaaS Services
  • Cloud Storage (Azure)
  • Virtual Datacenter
  • AI & Agent Hosting
  • Containers
  • Instant Apps
  • Software Platforms
  • Network builder
  • Game Servers
  • Free Game Servers
  • Pricing

Resources

  • Free Network Tools
  • 2026 Pricing Benchmark
  • Live SVG Badges
  • Latency & Speed Test
  • Guides & Tutorials
  • Documentation
  • API Reference
  • MCP Server
  • CLI & SDKs
  • OpenAPI & llms.txt
  • Use Cases
  • Free Migration
  • Uptime & Reliability
  • Datacenter
  • System Status
  • Network
  • Provider Comparisons Hub
  • Compare Providers

Company

  • About Us
  • Enterprise
  • Security Architecture
  • Trust Center
  • Blog
  • FAQ
  • Compliance
  • Startup Program
  • Open-Source Sponsorship
  • Press & Media Kit
  • Referral Program
  • Help Center
  • Contact Us
© Servers Are Up
TermsPrivacySLARefund PolicyDPAAcceptable Use
Service information
Docs
  • Documentation Hub
  • Technical Knowledge Library
    Runbooks & 187 Blueprints
  • Choose a Product
    VMs, Containers & Cloud
  • First Linux Server
    SSH, Firewall & Apps
  • Windows Server 2025
    BYOL & Remote Desktop
  • Remote Access
  • Troubleshooting
  • FAQ
  • All Product Guides
    33 Step-by-Step Guides
  • Cloud & SaaS Catalog
    139 Cloud & SaaS Offerings
  • Azure Cloud Storage
    Hot/Cool/Archive & WORM
  • Resource Manager & RBAC
    Groups, Tags & Locks
  • ARM/TF & Cloud Blueprints
    42-Type IaC & State
  • OCI Container Registry
    SBOM, CVE & Signing
  • Multi-Model Cloud DB
    JSONB, SQL & pgvector
  • Cloud Identity & ZTNA
    OIDC, SCIM & PIM
  • Per-Environment Tenant Suite
    Isolated Auth, SIEM & MCP
  • Secrets & KMS
    Secrets & Envelope Keys
  • Cloud SIEM, SOAR & DLP
    Posture & Threat Response
  • Data Lineage & DSPM
    Classification, EASM & DKE
  • API Gateway & Cloud DNS
    Edge WAF & DNS Zones
  • Serverless, Workflows & IoT
    Functions, Queues & DAGs
  • SaaS, Governance & Vault
    Budgets & Off-Host GRS
  • Linux Systems & Kernel
    SSH, UFW, sysctl & OOM
  • Self-Hosted Apps & Stacks
    Caddy, Nextcloud & Auth
  • Build Web Apps with AI
  • Next.js and React
  • TypeScript and Node.js
  • npm and Tooling
  • Data and APIs
  • Deploy and Operate
  • Tutorials
  • Infrastructure
  • Automation & Regions
  • API Overview
  • API v1 Reference
    Endpoints & 26 Scopes
  • MCP Server
    200 AI Agent Tools
  • Swagger / OpenAPI 3.1
  • API Playground
  • Versioning & Sunset
  • API Token Security
    Authentication & Tokens
  • Instances API
    Compute Resources
  • Networking API
    Networks & Ports
  • Storage API Availability
    Volumes & Backups
  • Webhooks & Events
    Event Notifications
  • Rate Limits & Best Practices
    Throttling & Retries
  • sau CLI Reference
    200 Commands (v0.3)
  • Browser Web CLI
  • SDKs
  • Infrastructure as Code
    Terraform & Ansible
  • Code Examples
  • CLI & SDK Guides
  • Security Guides
  • Security at a Glance
  • Zero Trust Architecture
  • Live Trust Center
  • Compliance
Need help?

Loading documentation...

Documentation/deploy operate

Run a Next.js app as a systemd service on Ubuntu

Build a Next.js 16 app in standalone mode and run it under systemd so it starts at boot, restarts on failure and logs to the journal.

Intermediate
25 min
Updated 2026-10-27

Deploy Ready-to-Run Infrastructure in Seconds

Linux VMs from $6/mo · Pooled Virtual Datacenters from $12/mo · Use code WELCOME20 for 20% off your first order.

Browse ServersView Pricing

Commands checked on 2026-10-27 with Next.js 16, Node.js 24, Ubuntu 24.04, systemd 255.

What you will have at the end

A Next.js app running on your server as a systemd service, under a user of its own that can write nowhere but the app's cache. It starts when the server boots, comes back by itself within seconds if it crashes, and writes its output to the journal, where journalctl reads it.

Before you start

  • An Ubuntu 24.04 server with a user that can use sudo, set up as in Set up a fresh Ubuntu 24.04 server safely.
  • At least 2 GB of memory for the build. A smaller server can run the app, but build it elsewhere and copy the result.
  • A Next.js app of your own, or the example made in step 2. The guide puts the app in /srv/nextapp and listens on port 3000 on the server itself; a web server in front of it (Nginx or Caddy) takes the public traffic.

Steps

1. Install Node.js 24

Ubuntu 24.04 ships Node.js 18, which Next.js 16 does not support. NodeSource publishes Node.js 24 as an apt repository. Download its setup script, read it if you like, then run it.

curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
node --version

The last command prints a version that starts with v24..

2. Make an app to run, or use your own

If you already have an app, skip to step 3 with its source in a folder on the server. Otherwise this makes the standard example, answering every question with its default:

npx --yes create-next-app@16 nextapp --ts --eslint --app --use-npm --yes
cd nextapp

3. Build in standalone mode

Standalone mode puts a minimal server and only the packages it needs in .next/standalone, so the server does not need the whole node_modules folder. Add the setting to the config, then build.

cat > next.config.ts <<'EOF'
import type { NextConfig } from "next";

const nextConfig: NextConfig = {
  output: "standalone",
};

export default nextConfig;
EOF
npm run build
ls .next/standalone

The build ends with a table of routes, and .next/standalone holds server.js, package.json, a node_modules folder and a .next folder.

4. Put the app in place with its own user

The standalone server does not copy the static files or the public folder; you copy them next to it (leave out the public line if your app has no such folder). The app runs as a system user that owns nothing but its cache folder.

sudo useradd --system --no-create-home --shell /usr/sbin/nologin nextapp
sudo install -d -m 755 /srv/nextapp
sudo cp -a .next/standalone/. /srv/nextapp/
sudo cp -a .next/static /srv/nextapp/.next/static
sudo cp -a public /srv/nextapp/public
sudo install -d -m 750 -o nextapp -g nextapp /srv/nextapp/.next/cache
sudo chown -R root:root /srv/nextapp
sudo chown nextapp:nextapp /srv/nextapp/.next/cache

5. Write the service

The unit names the user, the folder, the command and the environment, says to restart on failure, and takes away the rights the app does not need: it cannot write outside its cache folder, read home folders or gain new privileges.

sudo tee /etc/systemd/system/nextapp.service > /dev/null <<'EOF'
[Unit]
Description=Next.js app
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=nextapp
Group=nextapp
WorkingDirectory=/srv/nextapp
Environment=NODE_ENV=production
Environment=PORT=3000
Environment=HOSTNAME=127.0.0.1
ExecStart=/usr/bin/node server.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
ReadWritePaths=/srv/nextapp/.next/cache

[Install]
WantedBy=multi-user.target
EOF
sudo systemd-analyze verify /etc/systemd/system/nextapp.service

systemd-analyze verify prints nothing when the unit is valid.

6. Start it now and at every boot

enable --now starts the service and links it into the boot sequence in one command.

sudo systemctl daemon-reload
sudo systemctl enable --now nextapp
systemctl is-enabled nextapp
systemctl is-active nextapp

The last two lines read enabled and active.

Check that it works

Ask the app for its home page, then end its process the hard way and watch systemd bring it back:

curl -s --retry 5 --retry-connrefused --retry-delay 1 -o /dev/null -w '%{http_code}\n' http://127.0.0.1:3000/
sudo systemctl kill --kill-whom=main -s KILL nextapp
sleep 8
systemctl show nextapp -p ActiveState -p NRestarts
curl -s --retry 5 --retry-connrefused --retry-delay 1 -o /dev/null -w '%{http_code}\n' http://127.0.0.1:3000/
sudo journalctl -u nextapp -n 12 --no-pager

The app needs a second after it starts before it accepts connections, so curl tries again for a few seconds if the port is still closed. Both requests print 200. Between them systemctl show reads NRestarts=1 and ActiveState=active, and the journal shows Main process exited, code=killed, status=9/KILL, then Scheduled restart job, restart counter is at 1. five seconds later, and the app starting again.

What can go wrong

  • The service stops at once with Cannot find module '/srv/nextapp/server.js'. The build was not in standalone mode, so .next/standalone was never made. Check next.config.ts holds output: "standalone", then build and copy again.
  • The page loads without its styles, and files under /_next/static/ answer 404. The static folder was not copied next to the server. Copy .next/static to /srv/nextapp/.next/static and restart the service.
  • The journal shows EACCES or EROFS when a page is generated or an image is resized. The app is writing somewhere other than its cache folder, which the unit forbids. Add that folder to ReadWritePaths= if the app really needs it, run sudo systemctl daemon-reload, then restart.
  • The service restarts over and over. With RestartSec=5 systemd tries again every five seconds and never gives up, so a crash at start shows as a climbing NRestarts. sudo journalctl -u nextapp -n 50 shows the error each time. Fix the cause, then sudo systemctl restart nextapp.
  • curl answers from the server but the site is not reachable from outside. The app listens on 127.0.0.1 on purpose. Put a web server in front of it on the server, then serve that web server as the server's website: on the server's Console tab, under Website, give its port and click Serve website. The site then has its own address with HTTPS, private until you publish it.

Good practice

  • Build somewhere other than the server that serves traffic when you can, and copy only the standalone folder: the server then never runs npm install.
  • Keep the app's own user unable to write its code. A bug or a break-in then cannot change what runs at the next restart.
  • Put settings in Environment= lines or an EnvironmentFile= readable only by root, never in the repository.
  • To release a new version, copy it into a new folder, point the unit's WorkingDirectory= at it and restart. The old folder is your rollback.
  • Read sudo journalctl -u nextapp after every release, not only when something breaks.

Where to go next

  • Set up a fresh Ubuntu 24.04 server safely
  • Use the lockfile so every machine installs the same tree
  • Firewall Configuration

Related Articles

Tune Linux UDP sysctls, SteamCMD, FiveM, and PaperMC servers

Read more

Set up a fresh Ubuntu 24.04 server safely

Read more

Frequently Asked Questions

What does the Run a Next.js app as a systemd service on Ubuntu documentation guide cover?
Build a Next.js 16 app in standalone mode and run it under systemd so it starts at boot, restarts on failure and logs to the journal. It is rated intermediate difficulty (25 min) and applies to Servers Are Up infrastructure and workflows.
Can I manage or automate these steps through the Servers Are Up dashboard, REST API v1, or MCP server?
Yes. Every Servers Are Up server includes browser-based SSH, WebRDP, and VNC console access in the dashboard, plus programmatic control via the REST API v1 (/api/v1) and hosted Model Context Protocol server (/api/mcp/v1) using a scoped Personal Access Token.

Need hands-on help with Run a Next.js app as a systemd service on Ubuntu?

Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.

Was this article helpful?

On this page

What you will have at the endBefore you startSteps1. Install Node.js 242. Make an app to run, or use your own3. Build in standalone mode4. Put the app in place with its own user5. Write the service6. Start it now and at every bootCheck that it worksWhat can go wrongGood practiceWhere to go next
Need Live Commands?

Open Aria in Wide Engineering Mode for distro-specific commands, compose tweaks, and isolated environment troubleshooting.

Knowledge Library