Cara Deploy Next.js App ke VPS Ubuntu 24.04 — Step by Step Production 2026
Cara Deploy Next.js App ke VPS Ubuntu 24.04 — Step by Step 2026
Deploy Next.js ke VPS: Panduan production-ready untuk mendeploy aplikasi Next.js 15 ke VPS Ubuntu 24.04 dengan Nginx reverse proxy, PM2 process manager, SSL Let's Encrypt, environment variables, dan CI/CD.Artikel ini mencakup semua langkah dari setup server kosong hingga aplikasi live dengan HTTPS.
1. Setup VPS Ubuntu 24.04
sudo apt update && sudo apt upgrade -y
sudo apt install nginx certbot python3-certbot-nginx -y
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs -y
sudo npm i -g pm2
Biaya VPS 2 vCPU 4GB RAM: Rp 100.000-350.000/bulan di provider Indonesia (Niagahoster, IDCloudHost), atau $6-24/bulan di VPS luar (DigitalOcean, Vultr).
2. Clone dan Build Next.js
git clone https://github.com/user/repo.git /var/www/app
cd /var/www/app
npm install
cp .env.example .env # Edit values production
npm run build
Pastikan file .env berisi semua environment variable production: DATABASE_URL, API_KEY, NEXT_PUBLIC_URL, dll.
3. PM2 Process Manager
pm2 start npm --name "next-app" -- start
pm2 save
pm2 startup # Auto-start saat reboot
PM2 akan otomatis merestart aplikasi jika crash. Gunakan pm2 monit untuk monitoring real-time.
4. Nginx Reverse Proxy
server {
listen 80;
server_name yourdomain.com;
location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; }
}
FAQ — Deploy Next.js ke VPS
Berapa biaya VPS untuk Next.js production?
VPS 2 vCPU 4GB RAM cukup untuk Next.js app dengan traffic menengah: Rp 100.000-350.000/bulan di provider lokal Indonesia, atau $6-24/bulan di VPS internasional seperti DigitalOcean.
PM2 atau Docker?
- PM2: Lebih simpel, cocok untuk single app. Setup 5 menit. Auto-restart built-in.
- Docker: Lebih kompleks, cocok untuk multi-service microservices. Butuh orchestration.
- Untuk pemula: mulai dengan PM2, upgrade ke Docker saat perlu scale.
Kesimpulan
Deploy Next.js ke VPS tidak serumit yang dibayangkan. Dengan setup Nginx + PM2 + Let's Encrypt, aplikasi Anda siap production dalam 30 menit. Kunjungi EverDev Pro untuk tutorial development dan DevOps lainnya.