Deploy Aplikasi ke VPS: Nginx, SSL, dan CI/CD dari Nol di 2026
Deploy ke Vercel itu mudah, tapi kadang Anda butuh kontrol penuh atas server. Pelajari cara setup VPS Ubuntu, Nginx reverse proxy, SSL gratis dengan Certbot, dan CI/CD otomatis.
Muhamad Putra Aulia Hidayat
Deploy ke VPS: Full Control atas Server Anda
Vercel dan Railway memang nyaman, tapi ada kalanya Anda butuh VPS: database custom, software khusus, atau sekadar kontrol penuh atas infrastruktur. Ini panduan lengkap setup dari nol.
Pilih VPS yang Tepat
Untuk project kecil-menengah, rekomendasi kami:
| Provider | Spesifikasi | Harga/bulan |
|---|---|---|
| DigitalOcean | 2 vCPU, 2GB RAM | ~$18 |
| Vultr | 2 vCPU, 2GB RAM | ~$15 |
| Hetzner | 2 vCPU, 4GB RAM | ~$6 |
| Contabo | 4 vCPU, 8GB RAM | ~$8 |
Hetzner dan Contabo memberikan value terbaik. Hetzner terutama untuk server di Eropa dengan ping bagus ke Asia.
Setup Awal VPS Ubuntu 24.04
# Update sistem
apt update && apt upgrade -y
# Buat user non-root
adduser deploy
usermod -aG sudo deploy
# Setup SSH key (dari local machine)
ssh-copy-id deploy@your-server-ip
# Disable root SSH login
echo "PermitRootLogin no" >> /etc/ssh/sshd_config
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
systemctl restart sshd
# Setup firewall
ufw allow OpenSSH
ufw allow 80
ufw allow 443
ufw enable
Install dan Konfigurasi Nginx
apt install nginx -y
systemctl enable nginx
# /etc/nginx/sites-available/myapp
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
# Redirect ke HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header Strict-Transport-Security "max-age=31536000";
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_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
# Static files langsung dari Nginx (lebih cepat)
location /_next/static {
proxy_pass http://localhost:3000;
add_header Cache-Control "public, max-age=31536000, immutable";
}
}
ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx
SSL Gratis dengan Certbot
apt install certbot python3-certbot-nginx -y
certbot --nginx -d yourdomain.com -d www.yourdomain.com
# Certbot otomatis renew setiap 90 hari
systemctl status certbot.timer
Deploy Aplikasi dengan PM2
# Install Node.js via nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
nvm install 22
# Install PM2
npm install -g pm2
# Build dan start aplikasi
cd /var/www/myapp
npm install && npm run build
pm2 start npm --name "myapp" -- start
pm2 startup # Auto start saat reboot
pm2 save
CI/CD dengan GitHub Actions
# .github/workflows/deploy.yml
name: Deploy to VPS
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: deploy
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cd /var/www/myapp
git pull origin main
npm install
npm run build
pm2 reload myapp --update-env
echo "Deploy berhasil!"
Dengan setup ini, setiap kali push ke main, aplikasi otomatis ter-deploy dalam ~2 menit.
Zero-Downtime Deploy
# PM2 handle zero-downtime dengan cluster mode
pm2 start npm --name "myapp" -- start -i max
pm2 reload myapp # Reload satu per satu, tidak ada downtime
Mau kami bantu setup infrastruktur production untuk aplikasi Anda? Konsultasi sekarang.
Newsletter Digital Uptime
Tips teknologi & bisnis mingguan
Bergabung dengan 2,500+ subscriber yang mendapatkan insight teknologi, tutorial development, dan tips bisnis digital langsung ke inbox mereka setiap minggu.