Cloud, DevOps & Security 12 min read

How to Deploy a React and Node.js App on a VPS: Nginx, PM2 and Free SSL (Step by Step)

Deploy a full-stack app on an Ubuntu VPS from scratch: secure the server, install Node.js, run the API with PM2, serve React with Nginx, add a domain and HTTPS with Let’s Encrypt, and redeploy safely.

Umer Hasan

Umer Hasan

Co-Founder & CTO at Zapprex

How to Deploy a React and Node.js App on a VPS: Nginx, PM2 and Free SSL (Step by Step)
Table of contents

What we are building

A single Ubuntu server will host a React front end (static files served by Nginx) and a Node.js API (kept alive by PM2), behind your domain with free HTTPS. This setup works on any VPS provider — Hostinger, DigitalOcean, AWS Lightsail and others.

At a glance: Step 5: Redeploy without drama — Script it, Zero-downtime reloads, Back up the database, Monitor
At a glance: Step 5: Redeploy without drama

Step 1: Prepare and secure the server

Step 1: Prepare and secure the server: 5 steps
  1. 1

    Create the VPS: choose Ubuntu LTS, add your SSH key and note the server IP.

  2. 2

    Log in and update: run the system updates.

  3. 3

    Create a deploy user: avoid working as root day to day.

  4. 4

    Enable the firewall: allow only SSH, HTTP and HTTPS.

  5. 5

    Disable password login: allow SSH keys only.

Initial server setup (Ubuntu)bash
sudo apt update && sudo apt upgrade -y
sudo adduser deploy && sudo usermod -aG sudo deploy
sudo ufw allow OpenSSH && sudo ufw allow "Nginx Full" && sudo ufw enable
# in /etc/ssh/sshd_config set: PasswordAuthentication no — then:
sudo systemctl restart ssh

Step 2: Install Node.js, run the API with PM2

Node.js via nvm, app via PM2bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
source ~/.bashrc && nvm install --lts

git clone https://github.com/your-org/your-app.git && cd your-app/api
npm ci --omit=dev
cp .env.example .env   # then edit with real values

npm install -g pm2
pm2 start server.js --name api
pm2 save && pm2 startup   # restart automatically after reboot

Tip: Bind the Node API to 127.0.0.1 (for example port 4000) so it is reachable only through Nginx, not directly from the internet.

Step 3: Serve React and proxy the API with Nginx

/etc/nginx/sites-available/example.comnginx
server {
  server_name example.com www.example.com;
  root /var/www/example/dist;          # your React build output
  index index.html;

  location / {
    try_files $uri /index.html;        # client-side routing
  }

  location /api/ {
    proxy_pass http://127.0.0.1:4000;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}

Step 4: Domain and free HTTPS

  1. 1

    Point DNS: add A records for example.com and www to your server IP.

  2. 2

    Enable the site: link the config into sites-enabled, test with nginx -t and reload Nginx.

  3. 3

    Install Certbot: get a free Let’s Encrypt certificate with the Nginx plugin.

  4. 4

    Check renewal: Certbot sets up automatic renewal; confirm with a dry run.

Enable site and HTTPSbash
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot renew --dry-run

Step 5: Redeploy without drama

“If deploying needs a checklist in someone’s head, automate it. Repeatable deploys are safe deploys.”

— Umer Hasan, CTO
  • Script it: pull, install, build and restart in one deploy script — or automate it with CI/CD.
  • Zero-downtime reloads: use pm2 reload for the API.
  • Back up the database: before migrations, every time.
  • Monitor: PM2 logs, uptime checks and disk space alerts.

Topics

Deploy Node.jsVPS HostingNginxPM2React Deployment
Umer Hasan
Written by

Umer Hasan

Co-Founder & CTO at Zapprex

Leads engineering, cloud infrastructure and AI automation at Zapprex Technologies, with 7+ years of full-stack and mobile experience.

FAQ

Questions readers ask

A VPS gives full control and can be cheaper for always-on APIs, but you manage security and updates. Platforms like Vercel are simpler for front ends and serverless functions.

Have a project in mind?

Let's build something that moves your business forward.

Share your idea, process or problem — we will come back with a clear plan, timeline and cost range. No technical spec needed.

  • Founder reply within 1 business day
  • NDA on request · 100% code ownership
  • Talk directly to the engineers