FlexoHost Logo
FlexoHost Logo
Back to guides
VPS4 min readOct 29, 2026

Deploy a Node.js or Next.js App on a BDIX VPS (Ubuntu, Step by Step)

Deploy a Node.js or Next.js app on an Ubuntu VPS: secure the server, install Node with nvm, run with PM2, put Nginx in front, add free SSL and deploy updates.

FlexoHost Team

Technical guides & hosting tips

On this page
Deploy a Node.js or Next.js App on a BDIX VPS (Ubuntu, Step by Step)

This guide takes a fresh Ubuntu VPS to a running Node.js or Next.js app with HTTPS. It works on any Ubuntu 22.04/24.04 server; a BDIX VPS in Dhaka is a good choice when your users are in Bangladesh (BDIX VPS).

You need: a VPS with root access, a domain pointing to the VPS IP (A record), and your app in a Git repository.

1. Log in and update

ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y

2. Create a user and secure SSH

adduser deploy
usermod -aG sudo deploy
mkdir -p /home/deploy/.ssh && cp ~/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh

Then in /etc/ssh/sshd_config set PermitRootLogin no and PasswordAuthentication no (only after you confirmed key login works), and run systemctl restart ssh.

3. Turn on the firewall

ufw allow OpenSSH
ufw allow 'Nginx Full'
ufw enable

(If Nginx is not installed yet, allow ports 80 and 443 after step 6.)

4. Install Node.js with nvm

Log in as deploy, then:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc
nvm install --lts
node -v

5. Get your app and build it

git clone https://github.com/you/your-app.git ~/app
cd ~/app
npm ci
npm run build      # Next.js; skip for a plain Express app

Low on RAM during next build? Add a swap file:

sudo fallocate -l 2G /swapfile && sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Put secrets in a .env file (never commit it).

6. Run it with PM2

npm install -g pm2
pm2 start npm --name app -- start      # Next.js listens on port 3000 by default
pm2 save
pm2 startup                             # run the printed command once

Check with pm2 status and pm2 logs app.

7. Put Nginx in front

sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/app
server {
    listen 80;
    server_name example.com www.example.com;

    location / {
        proxy_pass http://127.0.0.1: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-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
sudo ln -s /etc/nginx/sites-available/app /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

8. Add free SSL

sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com

Certbot sets up HTTPS and automatic renewal. Test renewal with sudo certbot renew --dry-run.

9. Deploy updates

cd ~/app
git pull
npm ci
npm run build
pm2 reload app

Save this as deploy.sh to run with one command, or trigger it from GitHub Actions over SSH.

10. Keep it healthy

  • sudo apt install unattended-upgrades for automatic security updates
  • pm2 install pm2-logrotate so logs do not fill the disk
  • Back up your database and .env off the server
  • Monitor uptime with a free monitor (uptime monitoring guide)

Troubleshooting

Problem Check
502 Bad Gateway Is the app running? pm2 status; does the port match Nginx?
Build killed Out of memory: add swap or a bigger plan
Site not loading on domain DNS A record points to the VPS IP? Firewall allows 80/443?
Changes not visible Did you rebuild and pm2 reload?

Which VPS size?

App Suggested
Small API or Express app 1 vCPU, 1 GB RAM
Next.js site (with builds on server) 2 vCPU, 2 GB RAM
App + database (PostgreSQL/MySQL) 4 vCPU, 4 GB RAM

Prefer not to manage a server? Small apps can run on cPanel: Node.js app in cPanel. Comparing options: best VPS in Bangladesh.

সাধারণ জিজ্ঞাসা (FAQ)

What size VPS do I need for a Next.js app?

A small Next.js or Express app runs on 1 vCPU and 1 GB RAM, but building Next.js needs more memory; 2 GB is a comfortable start. Larger apps with a database need 4 GB.

Why use PM2?

PM2 keeps your Node.js process running, restarts it if it crashes, starts it on reboot and makes logs easy to read.

Why put Nginx in front of Node.js?

Nginx handles HTTPS, compression and static files efficiently, and forwards requests to your app on a local port.

How do I get free SSL?

Use Certbot with the Nginx plugin to get a free Let's Encrypt certificate that renews automatically.

Can I deploy Next.js on cPanel instead?

Yes, small apps can run with cPanel's Setup Node.js App, or you can upload a static export. A VPS gives more control and resources.

Why choose a BDIX VPS for a Node.js app?

If your users are in Bangladesh, a Dhaka BDIX VPS gives lower API and page latency than a server abroad.

Need fast hosting for your website?

NVMe SSD, LiteSpeed, free SSL and 24/7 support, with servers in Bangladesh (BDIX) and abroad.

Related guides

Need Help? We Are Here To Help You

Please feel free to consult with one of our experts, who will thoroughly evaluate your specific requirements and provide a tailored proposal that perfectly aligns with your company's unique needs and realities.