DevOps
Musaddaq Farid Tahir•August 18, 2026•7 min read
Complete Guide: Deploying Next.js 16 on Ubuntu VPS with Nginx & PM2
Why Self-Hosted VPS Deployment?
While platforms like Vercel are great for quick prototypes, hosting your client applications on a dedicated VPS gives you full control over CPU resources, custom background workers, and zero bandwidth overage costs.
Prerequisites
1. Ubuntu 24.04 LTS VPS instance
2. Registered domain name pointed to your VPS IP address
3. SSH terminal access
Step 1: Install Node.js & PM2
Log in to your server and run the following shell setup:
bash
# Update system repositories
sudo apt update && sudo apt upgrade -y
# Install Node.js v20 LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs nginx git
# Install PM2 Process Manager globally
sudo npm install -y -g pm2
Step 2: Configure Nginx Reverse Proxy
Create an Nginx configuration file at `/etc/nginx/sites-available/musaddaq.dev`:
nginx
server {
server_name musaddaq.dev www.musaddaq.dev;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Step 3: Enable SSL Certificate with Certbot
bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d musaddaq.dev -d www.musaddaq.dev
Now your custom Next.js application is running securely on production HTTPS!
Need Custom Web Engineering?
Chat on WhatsAppLet's build your Next.js project today
WhatsApp Direct: 03111122125