Step-by-step guide to deploy your Next.js app to a DigitalOcean droplet
This comprehensive guide will walk you through deploying your Next.js application to a DigitalOcean VPS using NextDeploy.
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
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
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'
}
}
}
}
Deploy your application:
nextdeploy deploy --target production
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.
Explore our comprehensive courses for deeper learning.