Back to Guides
Intermediate
25 min

Deploy to DigitalOcean VPS

Step-by-step guide to deploy your Next.js app to a DigitalOcean droplet

VPS
DigitalOcean
Production

Deploy to DigitalOcean VPS

This comprehensive guide will walk you through deploying your Next.js application to a DigitalOcean VPS using NextDeploy.

Prerequisites

  • DigitalOcean account
  • NextDeploy CLI installed
  • SSH key pair generated
  • Next.js application ready for deployment

Step 1: Create Your Droplet

  1. Log into your DigitalOcean dashboard
  2. Click "Create" → "Droplets"
  3. Choose Ubuntu 22.04 LTS
  4. Select Basic plan ($12/month recommended)
  5. Add your SSH key
  6. Create the droplet

Step 2: Initial Server Setup

Connect to your new droplet:

ssh root@your-droplet-ip

Update the system and install essential packages:

apt update && apt upgrade -y
apt install -y nginx nodejs npm git ufw

Step 3: Configure Security

Set up a firewall and create a deployment user:

ufw allow OpenSSH
ufw allow 'Nginx Full' 
ufw enable

# Create deploy user
adduser deploy
usermod -aG sudo deploy

Step 4: Configure NextDeploy

Update your local nextdeploy.config.js:

module.exports = {
  targets: {
    production: {
      type: 'vps',
      host: 'your-droplet-ip',
      user: 'deploy',
      path: '/var/www/my-app',
      env: {
        NODE_ENV: 'production'
      }
    }
  }
}

Step 5: Deploy

Deploy your application:

nextdeploy deploy --target production

Step 6: Configure Nginx

Set up Nginx as a reverse proxy:

server {
    listen 80;
    server_name your-domain.com;
    
    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Your application should now be live! Visit your droplet's IP address to see your deployed Next.js app.

Next Steps

  • Set up SSL with Let's Encrypt
  • Configure monitoring
  • Set up automated backups
  • Implement CI/CD pipelines

Ready for more advanced topics?

Explore our comprehensive courses for deeper learning.