Back to articles
Technology Insight

Building a Self-Healing Mini Cloud CDN with Automatic Failover Using Keepalived and Geolocation DNS on 3 Budget VPS

June 3, 2026

Introduction: The Challenge of High Availability on a Budget

For modern businesses, web application performance and availability are directly tied to revenue. Content Delivery Networks (CDNs) are the standard solution for reducing latency and ensuring uptime, but commercial enterprise solutions can quickly become cost-prohibitive. For startups, small-to-medium enterprises (SMEs), or specific regional projects, leveraging budget Virtual Private Servers (VPS) to build a custom infrastructure is a highly attractive alternative.

However, deploying a multi-node infrastructure introduces a critical challenge: high availability and intelligent traffic routing. If one VPS goes down, how do you ensure users are seamlessly redirected to an active node without manual intervention? This article provides a comprehensive, step-by-step engineering blueprint to build a Mini Cloud CDN system with automatic failover using three low-cost VPS instances, powered by Keepalived (VRRP) and Geolocation DNS.

The Architecture Overview

To achieve both low latency and high availability, our architecture splits the responsibilities between regional routing and local node redundancy. We will utilize three budget VPS instances distributed across two distinct geographical regions (for example, two nodes in Southeast Asia and one node in East Asia).

  • Region A (Primary High-Traffic Zone - e.g., Singapore): Contains two VPS nodes (Node 1 and Node 2). These nodes will operate in an Active-Passive or Active-Active cluster bound by a Virtual IP (VIP) managed by Keepalived.
  • Region B (Secondary Zone - e.g., Tokyo): Contains one VPS node (Node 3), serving regional users and acting as a geographic backup.

Traffic is first filtered by a Geolocation DNS provider (such as Route 53, Cloudflare Advanced DNS, or ClouDNS). Users from Region A are directed to the Virtual IP of the Singapore cluster, while users from Region B are directed to the Tokyo node. If Node 1 in Singapore fails, Keepalived instantly shifts the VIP to Node 2. If the entire Singapore data center faces an outage, the Geolocation DNS health checks will automatically reroute all traffic to Region B.

Component Breakdown: Why This Stack?

Before diving into configuration, it is essential to understand the core technologies driving this architecture:

1. Reverse Proxy & Caching Layer: Nginx

Nginx serves as the core CDN engine on each node. It caches static assets (images, CSS, JS) locally on the VPS NVMe drives and proxies dynamic requests back to your central origin server. Properly configured Nginx caching drastically reduces origin load and slashes Time to First Byte (TTFB).

2. High Availability Layer: Keepalived & VRRP

Keepalived implements the Virtual Router Redundancy Protocol (VRRP). It allows Node 1 and Node 2 in the same data center to share a single, floating Virtual IP address. The nodes constantly send heartbeat packets to each other. If the primary node stops responding, the secondary node claims ownership of the VIP in milliseconds. Note: This requires a VPS provider that supports floating IPs or BGP IP failover within the same private network layer.

3. Routing Layer: Geolocation DNS

While Keepalived handles local, localized infrastructure failures, Geolocation DNS handles global traffic distribution. It looks at the incoming user's IP address, determines their physical location, and responds with the A record of the nearest available infrastructure node.

Step-by-Step Implementation Guide

Step 1: Setting Up the Nginx Caching Nodes

First, install Nginx on all three VPS instances. We must configure Nginx to act as a reverse proxy cache. Create a dedicated cache zone in your global nginx.conf file:

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cdn_cache:10m max_size=10g inactive=60m use_temp_path=off;

Next, configure the virtual host block to handle the proxying and caching mechanics:

server {
    listen 80;
    server_name cdn.yourbusiness.com;

    location / {
        proxy_pass [http://your-origin-server.com](http://your-origin-server.com);
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        
        # Enable Caching
        proxy_cache cdn_cache;
        proxy_cache_valid 200 302 60m;
        proxy_cache_valid 404 1m;
        proxy_add_header X-Cache-Status $upstream_cache_status;
    }
}

Step 2: Configuring Keepalived for Local Failover (Region A)

On Node 1 (MASTER) and Node 2 (BACKUP) in Region A, install Keepalived via your package manager (apt-get install keepalived).

On Node 1 (Master), create the following configuration in /etc/keepalived/keepalived.conf:

vrrp_script chk_nginx {
    script "pidof nginx"
    interval 2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass secure_password
    }
    virtual_ipaddress {
        192.168.1.100 # Replace with your actual Floating/Virtual IP
    }
    track_script {
        chk_nginx
    }
}

On Node 2 (Backup), the configuration remains almost identical, except the state changes to BACKUP and the priority is lowered to 100:

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 100
    ...
}

The chk_nginx script continuously checks if Nginx is active. If Nginx crashes on Node 1, Keepalived automatically drops its priority, causing Node 2 to instantly assume control of the Virtual IP address.

Step 3: Geolocation DNS and Global Health Check Configuration

With local failover secured in Region A, we now configure the global layer. Log into your Geolocation DNS provider and establish the following routing logic:

  1. Rule 1 (Southeast Asia Traffic): Route queries for cdn.yourbusiness.com to the Virtual IP (VIP) of Region A (Singapore).
  2. Rule 2 (Rest of World / East Asia Traffic): Route queries for cdn.yourbusiness.com to the public static IP of Node 3 (Tokyo).

Crucially, enable DNS Health Checking. Set up an HTTP health check poking http:///healthz every 30 seconds for both the Region A VIP and Node 3 IP. If the VIP endpoint goes completely dark (meaning both Node 1 and Node 2 have failed or the network provider is down), the DNS provider will automatically alter its routing tables, sending Southeast Asian users to Node 3 in Tokyo instead. This creates a multi-layered, self-healing system.

Security and Optimization Considerations

Building your own CDN requires careful attention to detail regarding synchronization and security:

Pro-Tip: To ensure uniform content delivery, use automated tools like rsync or automated cron jobs to sync custom configuration files across all nodes. Furthermore, leverage Let's Encrypt with automated hooks to deploy SSL certificates across all three endpoints concurrently.

Additionally, consider implementing rate-limiting policies at the Nginx level on each node to protect your origin server from Distributed Denial of Service (DDoS) attempts targeting uncached dynamic endpoints.

Conclusion: Enterprise Resilience at a Fraction of the Cost

By combining Nginx caching, Keepalived VRRP clustering, and Geolocation DNS, you effectively eliminate single points of failure across your delivery infrastructure. If a single software service fails, Keepalived resolves it locally in milliseconds. If an entire cloud region encounters network degradation, Geolocation DNS redirects traffic globally.

This DIY Mini Cloud CDN architecture proves that with strategic planning and open-source tooling, businesses do not need massive enterprise budgets to deploy a fast, reliable, and highly available global content delivery solution.

Building a Self-Healing Mini Cloud CDN with Automatic Failover Using Keepalived and Geolocation DNS on 3 Budget VPS | DPTCloud