Skip to main content

🌐 How to Host Multiple React Projects on One VPS Using Subdomains (Nginx + PM2)

🌐 How to Host Multiple React Projects on One VPS Using Subdomains (Nginx + PM2)

Already running one app on your VPS and want to host another under a different subdomain like admin-abhinav.rohatech.site? Whether it's a second React or Node.js app, this guide walks you through the full setup using Nginx and PM2.

🔧 Step 1: Add DNS Record in GoDaddy

  1. Log in to your GoDaddy account.
  2. Go to the DNS settings for your domain rohatech.site.
  3. Click Add Record and add the following:
TypeNameValueTTL
Aadmin-abhinavYour VPS IP address1 Hour

This connects admin-abhinav.rohatech.site to your VPS.

📁 Step 2: Upload or Clone Your Second App


ssh root@your-vps-ip
cd /var/www
git clone https://github.com/your-second-app.git admin-app
cd admin-app
npm install
npm run build

Alternatively, upload it from your local machine using SCP:


scp -r /path/to/your-app root@your-vps-ip:/var/www/admin-app

⚙️ Step 3: Run the Second App on a Different Port

Use PM2 and a different port (e.g., 3002):


npm install -g serve
pm2 start serve --name "admin-app" -- -s build -l 3002
pm2 save

🌐 Step 4: Configure Nginx for the New Subdomain


nano /etc/nginx/conf.d/admin-abhinav.rohatech.site.conf

Paste the following configuration:


server {
    listen 80;
    server_name admin-abhinav.rohatech.site;

    location / {
        proxy_pass http://localhost:3002;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Then restart Nginx:


nginx -t
systemctl reload nginx

🔒 Step 5: Add SSL with Certbot


certbot --nginx -d admin-abhinav.rohatech.site

To force HTTPS redirection:


server {
    listen 80;
    server_name admin-abhinav.rohatech.site;
    return 301 https://$host$request_uri;
}

✅ Your Second App is Now Live!

You can now access it via:

https://admin-abhinav.rohatech.site

💡 Bonus Tips

  • List all apps: pm2 list
  • View logs: pm2 logs admin-app
  • Delete app: pm2 delete admin-app
  • Auto-start on boot:

pm2 startup
pm2 save

This setup lets you host multiple clean, secure apps under different subdomains on a single VPS. 🚀

Comments

Popular posts from this blog

How to Convert a Next.js Website into a PWA and TWA

🚀 Complete Guide: Converting Next.js to PWA & TWA Transform your Next.js website into a Progressive Web App and wrap it as an Android application using Trusted Web Activity. Every step explained in detail! 📋 Table of Contents What is a PWA? What is a TWA? Prerequisites & Setup Step 1: Convert Next.js to PWA Install Dependencies Configure next.config.js Create Web App Manifest Prepare App Icons Update Document Head Build and Test PWA Step 2: Wrap PWA as TWA Create Asset Links File Install Bubblewrap CLI ...

DevOps Best Practices

 # DevOps Best Practices: Your Ultimate Guide to Modern Software Development In today's fast-paced tech world, DevOps isn't just a buzzword – it's a game-changer. Let's dive into the essential practices that can transform your software development process. ![DevOps Lifecycle](https://blogger.googleusercontent.com/img/placeholder.png) ## 🔄 1. Continuous Integration (CI) - The Foundation Think of CI as your code's quality guardian. Every time developers push code, automated tests run to catch issues early. Here's what makes great CI: - Automated builds triggered with every commit - Comprehensive test suites running automatically - Code quality checks integrated into the pipeline - Quick feedback loops to developers **Pro Tip:** Start with simple automated tests and gradually build up your test suite. Remember, it's better to have a few reliable tests than many unreliable ones. ## 🚀 2. Continuous Delivery (CD) - From Code to Customer CD ensures your software ...

Ultimate Guide to Sending Data in React: Axios & Fetch Explained

Ultimate Guide to Sending Data in React using Axios and Fetch Whether you're building a login form, uploading files, or submitting a complex dataset to your backend, understanding how to send data in React is essential. In this comprehensive guide, we'll explore all the major ways to send data using Axios and the native Fetch API , including formats like JSON , form-data , x-www-form-urlencoded , and other advanced techniques. This guide is designed for developers from beginner to advanced levels, providing both theoretical understanding and practical implementation examples. By the end of this tutorial, you'll have a complete understanding of how data flows from React components to backend servers, and you'll know exactly which method to choose for different scenarios. 📌 Why Learn Different Data Formats? Before diving into implementation details, it's crucial to understand why different data formats exist...