On this page

Moving Next.js to a Linux VPS cuts unpredictable serverless overages. You also get direct control over Postgres, Redis, and background jobs.
The hard part is keeping your search rankings intact. One broken redirect or missing TLS chain can drop indexed pages within days.
In this guide, you’ll learn:
- How to audit live URLs and port
vercel.jsonredirects - How to run
output: 'standalone'behind PM2 and Nginx - How to cut over DNS with zero crawl errors
- What to check in Googlebot logs and backlinks after launch
Read on for the step-by-step workflow.
Why Teams Move Next.js to a Linux VPS
Managed serverless platforms make the first launch fast, yet costs climb quickly once image optimization, ISR revalidations, and high-traffic blog routes scale up. Moving to a Linux VPS with 2 GB to 8 GB of RAM gives you predictable monthly pricing and direct access to Postgres, Redis, and background workers on the same machine or private network.
The catch is that your team now owns the web server, TLS renewal, process supervision, and HTTP headers. Handle those layers methodically and Googlebot will see a faster origin rather than a disruptive site move.
Step 1: Audit URLs, Redirects, and Response Codes

Before provisioning a server, freeze a baseline snapshot of every public URL your Next.js app serves today.
- Export your live sitemap and top landing pages from Google Search Console, focusing on every URL that earns clicks or external links.
- Record exact status codes and redirect chains for trailing slashes,
wwwvs apex domains, and legacy routes defined innext.config.mjsorvercel.json. - Check canonical tags and robots headers. Make sure
X-Robots-Tag: noindexis never sent on production routes and thatNEXT_PUBLIC_SITE_URLmatches your exact canonical host.
Any redirect that previously lived in platform-specific vercel.json rules must move into next.config.mjs (redirects()) or your Nginx / OpenLiteSpeed vhost config so old URLs keep returning 301 Permanent Redirects instead of 404 Not Found.
Step 2: Provision Node.js, Swap, and Your Stack
Start with a clean Ubuntu 24.04 LTS or Debian 12 server located close to your primary audience. Lock down SSH, enable UFW for ports 22, 80, and 443, and install a current Node.js LTS release (v22+) rather than an outdated distro package.
If your VPS has 2 GB of RAM or less, add a 2 GB to 4 GB swap file right away. Running next build on a small VPS without swap is the most common reason initial deployments crash mid-compile.
At this stage, decide whether you want to manage Nginx and PM2 by hand or run a self-hosted control plane. Teams comparing deployment panels often review self-hosted Vercel alternatives such as Coolify, Dokploy, or Docker-based workflows before committing to manual systemd units. Whatever layer you choose, keep staging behind HTTP Basic Auth and a noindex header so search engines never index a preview IP or staging subdomain.
Step 3: Build With Standalone Output and PM2

Next.js includes a standalone build mode that traces only the files needed for production and trims deploy artifacts dramatically. Enable it in next.config.mjs:
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
};
export default nextConfig;
After running npm ci && npm run build, copy the public/ and .next/static/ directories into .next/standalone/ (or use a multi-stage Dockerfile that copies them automatically). Remember two environment variable rules:
NEXT_PUBLIC_*values are baked in at build time. Changing one requires a freshnext build.- Server-only secrets load at runtime. Keep them in your process manager or container environment, never committed to Git.
Start the Node server under PM2 (or systemd / Docker with restart: always) bound to 127.0.0.1:3000:
HOSTNAME=127.0.0.1 PORT=3000 pm2 start .next/standalone/server.js --name nextjs-app
pm2 startup
pm2 save
Test the local origin directly with curl -I http://127.0.0.1:3000 and confirm your homepage, key blog posts, /sitemap.xml, and /robots.txt all return HTTP 200 with full server-rendered HTML.
Step 4: Configure the Reverse Proxy and TLS
Never expose Node.js directly on port 80 or 443. Place Nginx, OpenLiteSpeed, or Caddy in front of 127.0.0.1:3000 to terminate TLS, enforce HTTP/2, compress responses, and forward client headers cleanly.
In Nginx, forward the original host and protocol headers so Next.js generates accurate canonical URLs and redirect locations:
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location /_next/static/ {
alias /var/www/app/.next/static/;
expires 365d;
add_header Cache-Control "public, immutable";
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
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;
}
}
Add a clean 301 redirect from HTTP to HTTPS and from your secondary host (www to apex, or apex to www) matching your existing canonical setup. Issue your Let’s Encrypt certificate before switching public DNS (using DNS-01 validation or Cloudflare Origin Certificates if proxied) so visitors and crawlers never hit a single SSL warning during cutover.
Step 5: Cut Over DNS Without Crawl Errors

Zero-downtime DNS migration depends on lowering TTL early and verifying the new server before the public sees it.
- Drop DNS TTL to 60 or 300 seconds at least 24 hours before the move.
- Test the VPS locally by pointing your domain to the new VPS IP in your local
/etc/hostsfile. Load your top 10 organic pages, verify images served through/_next/image, test form submissions, and checkrobots.txtandsitemap.xml. - Flip the A and AAAA records during a low-traffic window and keep the old host running for 48 hours so straggling DNS resolvers never fail.
If you run a CDN such as Cloudflare in front of the VPS, purge cached error responses right after cutover and verify that edge caching rules do not cache personalized Set-Cookie responses or block /_next/static/ assets.
Step 6: Verify Logs, Indexing, and Backlinks

The first 72 hours after switching DNS are when silent SEO regressions show up. Watch three signals immediately:
- Server access logs: Filter Nginx or OpenLiteSpeed logs for
Googlebotand check for spikes in 404, 410, 500, or 502 responses. Any 502 Bad Gateway during deploys means you should switch to blue-green container swaps or PM2 reload rather than restarting in place. - Google Search Console: Inspect 3 to 5 top landing pages using the live URL Inspection tool to confirm Google renders the page identically and sees the same canonical tag.
- External links pointing to moved URLs: If you reorganized routes during the server move, check that high-value inbound links still resolve to 200 or a single-hop 301. A practical backlink monitoring guide helps you track lost links, accidental
nofollowchanges, and broken target URLs after a migration.
Common Next.js Linux VPS Migration Mistakes
- Forgetting
vercel.jsonredirects: Platform redirects do not carry over automatically. Port every rule tonext.config.mjsor your reverse proxy before cutover. - Blocking
/_next/imageor missing sharp: Installsharpin production dependencies on your VPS so Next.js image optimization stays fast and does not inflate Largest Contentful Paint (LCP). - Zero-swap builds causing downtime: Running
npm run buildon the same 1 GB VPS serving live traffic can trigger the Linux OOM killer. Build in GitHub Actions or add swap and deploy pre-built Docker images. - Double redirects (
http->https://www->https://apex): Collapse protocol and hostname redirects into one single-hop 301 rule.
Next Steps
A clean Next.js Linux VPS migration is mostly preparation before DNS changes. Export your URL and redirect inventory first, verify output: 'standalone' behind a reverse proxy using /etc/hosts, and monitor Googlebot status codes for a full week after cutover.
Once your logs show steady 200 responses and fast Time to First Byte (TTFB), decommission the old hosting plan and lock in your automated deployment pipeline.