Blog / Others/ Self-Built CDN Acceleration: A Retrospective and Modern Alternatives

Self-Built CDN Acceleration: A Retrospective and Modern Alternatives

Introduction: The Current State of Self-Built CDN and BAE Services

This article was originally published in 2013, introducing a method to build a CDN acceleration service using the free quota of Baidu App Engine (BAE) and the Layer program. It is important to note that BAE's free service policy has long since changed; as of 2023 and beyond, the free quotas described are no longer available. The Layer project has also been unmaintained for years.

Therefore, this article serves primarily as a reference for technical principles and history. For readers seeking to build a CDN or find alternatives, we provide updated ideas and recommendations at the end.

Original Scheme: Core Principles and Free Quotas (Historical Context)

BAE once offered a free resource quota, allowing users to deploy web applications. Its Cloud Storage (Bucket) service was key to the self-built CDN, providing file storage and distribution capabilities.

Free Quota Overview (circa 2013):

  • Web App Traffic: 200MB/day inbound, 200MB/day outbound.
  • CPU Time: 1 CPU Hour/day.
  • Cloud Storage (Bucket): Free inbound traffic, 500MB/day outbound traffic, 5GB storage capacity.

By deploying a reverse proxy CDN program called "Layer," static resources (like images, CSS, JS) from an overseas origin server could be cached in BAE's Bucket, leveraging Baidu's domestic network nodes to accelerate access for users in China.

Original Tutorial Steps (Based on Layer)

1. Environment Setup and Installation

  1. Get the Program: Download the Layer project from GitHub (https://github.com/oott123/Layer).
  2. Create a BAE App: Create a "PC Iframe" type app in the BAE console and configure the PHP runtime.
  3. Create a Cloud Storage Bucket: Create a new Bucket in BAE and set its access permissions to "Public Read."
  4. Upload the Program: Deploy the Layer package to the BAE app space via online code package, SVN, or Git.

2. Configure the Layer CDN Service

The core configuration file is config.sample.inc.php. Key parameters to modify:

/**********Basic Settings**********/
define('STATIC_URL','http://www.your-original-site.com/'); // Origin URL
define('DOMAIN','your-bucket-name'); // Your Cloud Storage Bucket name
define('WELCOME_DOC',TRUE); // Show welcome page

After configuration, publish the app as "Online" in the BAE console.

3. Verify CDN Functionality

  1. Check Resource Paths: Visit your site and check if URLs for static resources (like images) have changed to your BAE app domain.
  2. Check the Bucket: Log into BAE Cloud Storage management to see if cached files and directories have been automatically created.
  3. WordPress Integration (Legacy): For WordPress sites, you could install the WP Super Cache plugin and enter your BAE app domain in its CDN settings.

4. Advanced Features

  • Hotlink Protection: Enable and set whitelist domains in the config file.
  • Manual Cache Purge: Purge specific file caches by accessing a URL like your-cdn-domain/purge/file-path.
  • Memory Caching: Enable Memcached service in BAE for performance.
  • Custom Domain: Bind a domain in BAE backend and set its CNAME record to the address BAE provides.

Common Issues and Notes (Based on Original Scheme)

  • Slow First Visit: The CDN needs to fetch and cache files from the origin, making the first access slower.
  • CSS/JS Loading Issues: If styles or scripts break, exclude these file types from acceleration in CDN config or caching plugins.
  • Program Versatility: Layer is PHP-based and could theoretically be deployed on any PHP-supported host for reverse proxy and caching.

Updated Recommendations: Current Viable Alternatives

Since the original services are unavailable, here are more feasible approaches (post-2023):

  1. Use Object Storage + CDN Services: Major cloud providers (e.g., Alibaba Cloud, Tencent Cloud, Upyun) offer object storage with integrated CDN acceleration, often with free tiers and paid plans, providing easier management.
  2. Use Open-Source Reverse Proxy Software: Deploy Nginx or Caddy on your own VPS, configuring reverse proxy and caching to build a simple custom CDN. This requires server administration knowledge.
  3. Leverage Globally Distributed Edge Platforms: Services like Cloudflare Workers, Vercel Edge Functions, or Fly.io allow running JavaScript/WebAssembly code on edge nodes for flexible caching and forwarding logic, often with free tiers.
  4. Integrated Solutions: Host static resources on free static hosting platforms like GitHub Pages, Netlify, or Vercel, which typically include built-in CDN, and point your domain via CNAME.

Conclusion: The core value of a self-built CDN is control and flexibility, but it requires maintenance. For most personal site owners and small projects, using established cloud provider object storage + CDN combos is often a more stable, efficient, and cost-effective choice.

Post a Comment

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