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 type | When it is read | Where to set it |
|---|---|---|
NEXT_PUBLIC_* | At build time; inlined into the browser JavaScript | In the build environment (CI or the shell running next build) |
| Other variables (secrets, database URLs) | At run time on the server | In 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/imageworks when self-hosted. Installsharpas 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.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
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.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check 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
| Symptom | Cause 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 browser | NEXT_PUBLIC_ variable changed without rebuilding |
| Site reachable on port 3000 from outside | Server bound to 0.0.0.0; set HOSTNAME=127.0.0.1 |
| Images fail to optimise | Install sharp; check write permissions on the cache directory |
Frequently Asked Questions
Can I self-host Next.js without Vercel?
What does output: 'standalone' do?
.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?
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?
How do I use multiple CPU cores with Next.js?
Does next/image work on a VPS?
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?
/_next/static/ are fingerprinted, so they can be cached for a year with Cache-Control: public, max-age=31536000, immutable.