Back to articles
AI & Cloud

Building a Simple CDN System with Multiple VPS Located in Different Regions: A Practical Guide for Businesses

A detailed guide on building a simple CDN using multiple VPS in different regions, optimizing performance, reducing latency, and improving content delivery for businesses. Includes...

DPTCloud Engineering4 min read
Building a Simple CDN System with Multiple VPS Located in Different Regions: A Practical Guide for Businesses

Introduction to a Simple CDN System with Multiple VPS

A Content Delivery Network (CDN) accelerates content delivery by caching and serving content from geographically distributed servers. For small and medium-sized businesses, building a simple CDN using multiple Cloud VPS in different regions offers a cost-effective and flexible solution. This guide walks through setting up a self-hosted CDN using VPS instances across various regions to reduce latency, improve performance, and ensure high availability.

Requirements and Necessary Equipment

To deploy this simple CDN system, you will need:

  • At least 3 VPS instances in different regions (e.g., Singapore, Vietnam, USA)
  • Public IP addresses for each VPS
  • A main server (can be a VPS or physical server) to manage and distribute content
  • A DNS provider (such as Cloudflare, AWS Route 53, or self-hosted with BIND)
  • Content delivery software (e.g., Nginx, Caddy, or Varnish)

Setting Up the CDN System

We will use High-RAM Cloud VPS to host content delivery services. Below are the setup steps:

Step 1: Install and Configure VPS

On each VPS, install Nginx to serve static content:

sudo apt update
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx

Modify the Nginx configuration file to define the content directory:

server {
    listen 80;
    server_name _;
    root /var/www/html;
    index index.html;
}

Step 2: Create CDN Content

Create an index.html file in the /var/www/html directory on each VPS:

<html>
<head>
    <title>CDN Node - <hostname></title>
</head>
<body>
    <h1>This is CDN Node at <hostname></h1>
</body>
</html>

Run the following command to retrieve the hostname:

hostname

Step 3: Configure DNS

Use your DNS provider to create A records for each VPS:

  • cdn1.example.com → IP of VPS 1 (Singapore)
  • cdn2.example.com → IP of VPS 2 (Vietnam)
  • cdn3.example.com → IP of VPS 3 (USA)

Alternatively, use a CNAME record to distribute content via a main domain:

cdn.example.com.    CNAME   cdn1.example.com.

Perform Testing and Optimization

To test performance and latency, use the following commands:

# Check latency to each node
ping cdn1.example.com
ping cdn2.example.com
ping cdn3.example.com

# Check content load speed
curl -s -o /dev/null -w "%{time_total}\\n" http://cdn1.example.com
curl -s -o /dev/null -w "%{time_total}\\n" http://cdn2.example.com
curl -s -o /dev/null -w "%{time_total}\\n" http://cdn3.example.com

Security and Optimization Solutions

  • Set up SSL/TLS using Let's Encrypt:
  • sudo apt install certbot -y
    sudo certbot certonly --nginx -d cdn1.example.com
    
  • Integrate caching with Nginx:
  • location / {
        proxy_cache my_cache;
        proxy_cache_valid 200 302 10m;
        proxy_cache_valid 404 1m;
        proxy_pass http://localhost:8080;
    }
    

Troubleshooting Solutions

  • If content fails to load: check firewall rules, verify Nginx configuration, and validate DNS settings.
  • If latency is high: verify VPS location, test network connectivity, and consider edge CDN optimization.
  • If SSL errors occur: check system time and renew Let's Encrypt certificates.

Reference Materials

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478