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.

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.

Step 1: Prepare and secure the server

- 1
Create the VPS: choose Ubuntu LTS, add your SSH key and note the server IP.
- 2
Log in and update: run the system updates.
- 3
Create a deploy user: avoid working as root day to day.
- 4
Enable the firewall: allow only SSH, HTTP and HTTPS.
- 5
Disable password login: allow SSH keys only.
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 sshStep 2: Install Node.js, run the API with PM2
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 rebootTip: 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
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
Point DNS: add A records for example.com and www to your server IP.
- 2
Enable the site: link the config into sites-enabled, test with nginx -t and reload Nginx.
- 3
Install Certbot: get a free Let’s Encrypt certificate with the Nginx plugin.
- 4
Check renewal: Certbot sets up automatic renewal; confirm with a dry run.
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-runStep 5: Redeploy without drama
“If deploying needs a checklist in someone’s head, automate it. Repeatable deploys are safe deploys.”
- 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
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.
Keep reading
All articlesOTP Login Done Right: Security, Rate Limits, Autofill and SMS vs WhatsApp OTP
Build OTP login that is secure, cheap and pleasant: how OTPs should be generated and stored, rate limiting, SMS pumping fraud, autofill on Android, iOS and the web, and when to use WhatsApp or voice OTP.
Web Application Security Checklist: 25 Must-Do Steps Based on the OWASP Top 10
A practical, plain-English security checklist for websites and web apps: access control, injection, authentication, secrets, dependencies, headers, logging and backups — mapped to the OWASP Top 10.
API Security Best Practices: Authentication, Authorisation, Rate Limiting and More
How to secure REST and GraphQL APIs used by mobile apps and websites: tokens and keys, object-level authorisation, input validation, rate limits, CORS, webhooks and logging — with simple examples.
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.
Small apps run comfortably on 1–2 GB RAM. Add more if you run a database on the same server or expect higher traffic.
Yes. Let’s Encrypt certificates are free, trusted by browsers and renew automatically with Certbot.
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
