Application Hosting13 min read•Updated November 2026

How to Deploy a Next.js Application on a VPS

Quick answer

Install a current Node.js LTS release, set output: 'standalone' in next.config.js, run npm ci && npm run build, then copy .next/static and public into .next/standalone and start it with node server.js on 127.0.0.1:3000 under systemd or PM2. Put Nginx in front for HTTPS and long-term caching of /_next/static/. Remember that NEXT_PUBLIC_* variables are fixed at build time.

Next.js does not require a specialised hosting platform. Self-hosting on a VPS supports server rendering, API routes, middleware, image optimisation and incremental static regeneration, and it gives you predictable monthly costs. What you take on is running the Node.js server reliably and handling the details that managed platforms hide: build memory, environment variables, static asset caching and restarts.

Step 1: Install Node.js LTS

Use an actively supported LTS release of Node.js that your Next.js version supports (check the engines field and the Next.js documentation). Install it from NodeSource or with a version manager such as nvm; Ubuntu's own nodejs package is often older than Next.js requires.

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
node -v && npm -v

Review any script before piping it to a shell; NodeSource also documents a manual repository setup.

Step 2: Enable Standalone Output

Standalone output makes Next.js trace exactly which files and node_modules the server needs and copy them into .next/standalone. The result is far smaller than the full project and starts with a plain node server.js.

// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'standalone',
};
module.exports = nextConfig;

Step 3: Build

Build in CI if you can; Next.js builds are CPU- and memory-intensive, and building on a small production server can make the live site slow or trigger the out-of-memory killer. If you build on the server, make sure it has swap and enough RAM.

npm ci
npm run build
# standalone output does not copy static assets automatically:
cp -r public .next/standalone/
cp -r .next/static .next/standalone/.next/

Forgetting the two cp commands is the most common self-hosting mistake: pages render, but CSS, JavaScript and images return 404.

Step 4: Environment Variables (Build Time vs Run Time)

Variable typeWhen it is readWhere to set it
NEXT_PUBLIC_*At build time; inlined into the browser JavaScriptIn the build environment (CI or the shell running next build)
Other variables (secrets, database URLs)At run time on the serverIn the service's environment file

Changing a NEXT_PUBLIC_ value therefore requires a rebuild. Never put secrets in NEXT_PUBLIC_ variables: anything inlined into the client bundle is visible to every visitor.

Step 5: Upload and Run the Server

sudo adduser --system --group --home /opt/web web
rsync -a --delete .next/standalone/ deploy@server:/tmp/web-release/
ssh deploy@server 'sudo rsync -a --delete /tmp/web-release/ /opt/web/app/ && sudo chown -R web:web /opt/web/app'

Create /opt/web/.env (mode 600, owned by web) with your runtime variables, then a systemd unit /etc/systemd/system/web.service:

[Unit]
Description=Next.js site
After=network.target

[Service]
User=web
Group=web
WorkingDirectory=/opt/web/app
EnvironmentFile=/opt/web/.env
Environment=NODE_ENV=production
Environment=PORT=3000
Environment=HOSTNAME=127.0.0.1
ExecStart=/usr/bin/node server.js
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now web
curl -I http://127.0.0.1:3000

HOSTNAME=127.0.0.1 makes the standalone server listen only on localhost. PM2 works equally well if you already use it; see our PM2 guide. The standalone server is a single Node.js process; to use more cores, run several instances on different ports behind an Nginx upstream.

Step 6: Nginx, Caching and HTTPS

upstream nextjs {
    server 127.0.0.1:3000;
    keepalive 16;
}

server {
    listen 80;
    server_name example.com www.example.com;

    # Fingerprinted build assets never change: cache for a year
    location /_next/static/ {
        proxy_pass http://nextjs;
        proxy_set_header Host $host;
        add_header Cache-Control "public, max-age=31536000, immutable";
    }

    location / {
        proxy_pass http://nextjs;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d example.com -d www.example.com

Next.js already sends long cache headers for /_next/static; the explicit header above simply makes the intent clear if other caches sit in front. Gzip or Brotli compression can be done by Nginx or left to Next.js; enable it in one place only.

Self-Hosting Specific Features

  • Image optimisation: next/image works when self-hosted. Install sharp as a dependency for faster processing; recent Next.js versions use it automatically when available.
  • ISR and the data cache: regenerated pages are stored on disk under .next, so the service user must be able to write there. With several instances, each keeps its own cache unless you configure a shared cache handler.
  • Middleware: runs inside the Node.js server, no extra setup.
  • Several apps: give each its own port and Nginx server block, as in our multiple-apps guide.

Updating Without Long Downtime

Build the new version first, sync it into a new directory, then switch and restart:

# one time only: turn the first deploy into a release and point a symlink at it
sudo mkdir -p /opt/web/releases
sudo mv /opt/web/app /opt/web/releases/initial
sudo ln -s /opt/web/releases/initial /opt/web/app

# every update
REL=/opt/web/releases/$(date +%s)
sudo rsync -a /tmp/web-release/ $REL/ && sudo chown -R web:web $REL
sudo ln -sfn $REL /opt/web/app
sudo systemctl restart web

ln -sfn replaces the symlink in one step. It only works on a symlink: if /opt/web/app were still a real directory, the link would be created inside it, which is why the one-time step converts it first.

Restarting a single instance causes a few seconds of 502 errors while Node.js starts. Two instances behind the upstream, restarted one at a time, avoid that.

SkyRainCloud Plans for This Workload

Next.js server rendering is CPU-bound and builds are memory-hungry. A single site runs well on 2 vCores / 8 GB; build on CI or move to 4 vCores / 16 GB when you build on the server or host several Next.js apps.

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Troubleshooting

SymptomCause and fix
CSS/JS 404 in production.next/static or public not copied into .next/standalone
Build killed / "JavaScript heap out of memory"Not enough RAM for the build; build in CI, add swap, or raise NODE_OPTIONS=--max-old-space-size
Wrong API URL in the browserNEXT_PUBLIC_ variable changed without rebuilding
Site reachable on port 3000 from outsideServer bound to 0.0.0.0; set HOSTNAME=127.0.0.1
Images fail to optimiseInstall sharp; check write permissions on the cache directory

Frequently Asked Questions

Can I self-host Next.js without Vercel?
Yes. Next.js runs on any Node.js server. Server rendering, API routes, middleware, image optimisation and ISR all work when self-hosted.
What does output: 'standalone' do?
It copies only the files and dependencies the production server needs into .next/standalone, which you start with node server.js. You must copy public and .next/static into it yourself.
Should I build Next.js on the VPS or in CI?
In CI when possible. Builds use a lot of CPU and memory and can slow the live site. Build on the server only if it has spare RAM and swap.
Why doesn't my environment variable change take effect?
NEXT_PUBLIC_* variables are inlined at build time, so you must rebuild. Server-only variables are read at runtime from the service environment.
PM2 or systemd for Next.js?
Both are fine. systemd is built in and integrates with the journal; PM2 adds a convenient process list, log viewer and cluster mode.
How do I use multiple CPU cores with Next.js?
Run several instances on different ports and load-balance them with an Nginx upstream, or use PM2 cluster mode. Keep in mind each instance has its own ISR cache unless shared.
Does next/image work on a VPS?
Yes. Install the sharp package for fast image processing and make sure the server can write to its cache directory.
How do I cache static files with Nginx?
Files under /_next/static/ are fingerprinted, so they can be cached for a year with Cache-Control: public, max-age=31536000, immutable.
How much RAM does a Next.js site need?
A running server often uses a few hundred MB, but builds can need several GB. 8 GB is comfortable for one site; build elsewhere or choose 16 GB for several sites or on-server builds.
Which SkyRainCloud plan suits Next.js?
The 2 vCore / 8 GB AMD EPYC or Intel plan runs a typical Next.js site. Choose 4 vCores / 16 GB for heavy server rendering, several sites or building on the server.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning