Set up a simple self-service CDN

What is a CDN?

A content delivery network or content distribution network (CDN) is a geographically distributed network of proxy servers and The goal is to distribute service spatially relative to end-users to provide high availability and high accessibility to their data centers. CDNs serve a large portion of the Internet content today, including web objects (text, graphics and scripts), downloadable objects (media files, software, documents), applications (e-commerce, portals), live streaming media, on-demand streaming media, and social media sites.

CDN Wikipedia

My simple need for a CDN

Now the blog is on the server of American West, the access delay is acceptable.
But if there are a lot of pictures in the article, it will still be obvious, so I plan to use the CDN to speed up some of the main static files.

Select CDN

In China, there are too few CDN options, and almost certainly no service provider can fully meet the requirements,

  • :: HTTPS support
  • :: Support for HTTP/2
  • Support TLS1.3
  • Support for custom domain names

So with reference to the current simple needs of CDNs, I decided to set up a simple CDN myself.

How to set up a simple CDN by yourself

First we need to achieve the goal of having different domains pointing to different servers when accessing the same domain from different regions:

  • Anycast
  • :: DNS partition resolution

Anycast is currently not available in China for policy reasons, so it is the only way for us to get DNS partitioning.
Fortunately, NS1 currently offers free DNS partitioning.
NS1 can even resolve by state in the U.S., but it’s not provincial specific for mainland China, which is perfectly fine with me.

Now we just need to deploy the servers according to the DNS partitioning resolution zones.
The easiest and most straightforward way to do this is to use Nginx’s reverse proxy feature.

A simple CDN can be set up by using Nginx’s own proxy_cache module to configure the caching rules at all levels after getting through the network.

—Now a simple CDN can be set up.


The whole process of setting up a simple CDN did not actually create anything, but just integrated existing resources/services to meet the initial requirements.
It is not a complete solution for commercial CDN, but it is enough to use it by itself.