#StatPorn 3 Continent CDN

CDN $25.00 dollars

dollars 1 hour setup

For a fun weekend project, we decided to roll our own CDN using Go GeoDNS, DigitalOcean, Docker and Nginx.

DIGITALOCEAN + NGINX + DOCKER

Step 1: Order a DNS instance from DigitalOcean.

We chose SFO and the 2nd smallest instance.

We setup DNS info to point here (both NS1 and NS2 point here for ease of setup). These are A records.

ns1.deploy.io 192.241.224.116 ns2.deploy.io 192.241.224.116

Step 2: Install Docker and run with “coocood/geodns” image on the DNS instance

See https://index.docker.io/u/coocood/geodns for detail.

Step 3: Order the CDN “edge” instances for Nginx from DigitalOcean.

We used the smallest instance. We setup DNS for this example using them:

test-sfo-do.deploy.io 107.170.251.75 San Francisco $5/mo test-jfk-do.deploy.io 107.170.45.174 New York $5/mo test-sin-do.deploy.io 128.199.216.96 Singapore $5/mo test-ams-do.deploy.io 188.226.185.173 Amsterdam $5/mo

Here’s what DigitalOcean’s web interface looks like with all the machines spun up:

Digital Ocean SSD Cloud Server, VPS Server, Simple Cloud Hosting

Setup 4: Setup a test domain for the CDN:

If you lookup deployiotest.com the 4 web servers are chosen randomly

If you look up www.deployiotest.com, it will go to the closest geo server.

Set the name servers to point to:

ns1.deploy.io 192.241.224.116 ns2.deploy.io 192.241.224.116

which we setup earlier.

SEE THE CDN GEO DNS WORKING

Using whatsmydns.net (a great tool from Daniel) you can see that we are returning geo enabled results for our test domain “www.deployiotest.com”

What’s My DNS? whatsmydns.net is an online service that allows you to instantly perform a DNS lookup to check a hostnames current IP Address and other DNS information against a selection of random name servers around the world.

{ "serial":1394372421, "ttl": 390, "targeting": "country continent @ regiongroup region ip asn", "data":{ "":{ "ns": ["ns1.deploy.io", "ns2.deploy.io" ], "random":[ [ "107.170.45.174", "1000" ], [ "128.199.216.96", "1000" ], [ "107.170.251.75", "1000" ], [ "188.226.185.173", "1000" ] ] }, "www":{ "alias": "" }, "www.us-west":{ "cname": "test-sfo-do.deploy.io." }, "www.europe":{ "cname": "test-ams-do.deploy.io." }, "www.asia":{ "cname": "test-sin-do.deploy.io." }, "www.us-east":{ "cname": "test-jfk-do.deploy.io." } } }

Step 5: Verify that your CDN is working using JustPing.com

Just test it on www.just-ping.com.

Todo

:

Note: a comment from akerl_ on HN pointed out “the article doesn’t point out the serious risk of running a single DNS server for the records”. It’s a good point. Think before production – this is intended as an example Add a way to take servers in and out of rotation using a little daemon on the geodns server Tune the Geo map for places outside of the US/Europe and Asia. Add more virtual servers from other providers Add a way to spin up servers using lib-cloud

Thank you to Ewan Chou with this post. Ewan is a go developer based out of China. He likes working on efficient low level code. His github profile is located here.

Conclusion:

Do you enjoy working on this kind of stuff? Make it your full time gig and come work with us!

Popular search terms: