Skip to main content

🌐 How to Host Multiple Projects on One VPS Using Subdomains (admin-abhinav.rohatech.site)

🌐 How to Host Multiple 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 Next.js project or any Node.js app, this guide will walk you through adding multiple subdomain apps on a single server using Nginx and PM2.


🔧 Step 1: Add DNS Record in GoDaddy

  1. Log in to GoDaddy.
  2. Go to the DNS settings for your domain rohatech.site.
  3. Click Add Record.

Add the following DNS record:

Type Name Value TTL
A admin-abhinav Your VPS IP address 1 Hour

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


📁 Step 2: Upload or Clone Your Second App

SSH into your VPS and place your second app in a new directory:

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 the project using scp or FTP if you're working locally.


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

Use PORT=3002 to avoid conflict with other apps, and manage it using PM2:

PORT=3002 pm2 start npm --name "admin-app" -- start
pm2 save

This keeps the app running in the background and ensures it restarts on reboot.


🌐 Step 4: Configure Nginx for the New Subdomain

Create a new Nginx config file for admin-abhinav.rohatech.site:

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

Paste this:

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;
    }
}

Save the file and restart Nginx:


nginx -t
systemctl reload nginx

🔒 Step 5: Add SSL with Certbot

Use Let’s Encrypt to secure the subdomain with HTTPS:


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

Certbot will configure your Nginx file automatically and apply SSL.

Optional: Force Redirect HTTP to HTTPS

Add this block in Nginx for auto-redirect:

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 your second app via:

https://admin-abhinav.rohatech.site


💡 Bonus Tips

  • Use pm2 list to see all running apps.
  • Check logs with pm2 logs admin-app.
  • To remove an app: pm2 delete admin-app
  • Set all apps to run on boot: pm2 startup then follow the instructions

Now you can run multiple apps on different subdomains — clean, secure, and scalable! 🚀

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 ...

How to Keep ADB Connected Over Phone Hotspot (Automatic Reconnect)

How to Keep ADB Connected Over Phone Hotspot (Automatic Reconnect) How to Keep ADB Connected Over Your Phone Hotspot This is a simple, step-by-step guide to keep your ADB connection over a phone hotspot using Windows. No CSS or JavaScript is used. Step 1: Prerequisites Windows PC with ADB installed (part of Android Platform Tools). Phone with USB debugging enabled in Developer Options. Phone and PC connected to the same hotspot network. Step 2: Enable ADB over Wi-Fi (Temporary) Connect your phone to PC via USB and open Command Prompt or PowerShell, then run: adb devices adb tcpip 5555 adb shell ip route # optional, shows phone IP After this, you can unplug the USB cable. Step 3: Connect over Wi-Fi Run the following command with your phone's IP: adb connect <phone-ip>:5555 adb devices # to check connection You should see your device listed as connected over Wi-Fi. Step 4: Automatic Reconnect Scri...