How to Host Multiple Domains on a Single DigitalOcean Droplet Using Nginx
April 29, 2025

How to Host Multiple Domains on a Single DigitalOcean Droplet Using Nginx

🌐 Hosting Multiple Domains on a Single DigitalOcean Droplet with Nginx

When building modern web applications, it’s common to manage multiple domains or subdomains. Whether you’re serving multiple frontends, staging environments, or microservices, handling them all from a single server can be powerful and cost-effective.

In this guide, we’ll walk through how to host two domains on one DigitalOcean droplet using Nginx as the web server and Certbot for free SSL via Let’s Encrypt.

🧩 What We’re Setting Up

  • Two domains (e.g., abc.example.com and app.example.com)
  • Both domains pointed to the same server IP
  • Nginx configured to serve each domain individually
  • SSL (HTTPS) enabled for each domain using Certbot
  • Backend API routes proxied to a running application (e.g., Django or Node.js)

🛠️ Prerequisites

Before you start, make sure you have:

  • A Linux-based server (e.g., Ubuntu 22.04) with a public IP (e.g., 123.123.123.123)
  • Domains/subdomains purchased and managed via a DNS provider
  • Nginx installed:
sudo apt update && sudo apt install nginx -y
  • Certbot installed for SSL:
sudo apt install certbot python3-certbot-nginx -y

🌐 Step 1: Point Your Domains to the Server

Go to your domain registrar or DNS provider and create the following A records:

HostTypeValue
abc.example.comA123.123.123.123
app.example.comA123.123.123.123

Allow a few minutes for DNS propagation.

⚙️ Step 2: Create Nginx Configurations

Create separate config files for each domain inside /etc/nginx/sites-available.

For abc.example.com:

sudo nano /etc/nginx/sites-available/abc.example.com

Paste:

server {
    listen 80;
    server_name abc.example.com;

    root /path/to/your/frontend;
    index index.html;

    location / {
        try_files $uri /index.html;
    }

    location /api/ {
        proxy_pass http://localhost:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Do the same for app.example.com, with its own path and server block.

🔗 Step 3: Enable the Sites

Create symbolic links to enable the Nginx configurations:

sudo ln -s /etc/nginx/sites-available/abc.example.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/app.example.com /etc/nginx/sites-enabled/

Then reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

🔒 Step 4: Secure with HTTPS Using Certbot

Run Certbot to install SSL certificates:

sudo certbot --nginx -d abc.example.com
sudo certbot --nginx -d app.example.com

Certbot will automatically:

  • Request SSL from Let’s Encrypt
  • Update Nginx configuration
  • Reload the web server

✅ Done! Your Setup Is Live

You can now visit:

  • https://abc.example.com
  • https://app.example.com

Both will:

  • Serve their respective frontend apps
  • Securely handle API proxying
  • Be protected with valid SSL certificates

🔁 Bonus: Auto-Renew SSL

Let’s Encrypt certificates renew automatically. You can verify it with:

sudo certbot renew --dry-run

🧠 Final Thoughts

This approach scales well whether you’re hosting landing pages, admin panels, APIs, or microservices. With Nginx and a clean domain strategy, your infrastructure stays flexible and future-proof.

Table of Contents

Book a Discovery Call

SHARE ON

Leave a Reply

Your email address will not be published. Required fields are marked *