How to make your own CDN with 10 GB storage for free

By Darren Nathanael on Tue, Dec 14, 2021 / Updated at Wed, Feb 14, 2024

Hello there πŸ‘‹

Today we will use Cloudflare & GitLab to make the best β€œfree” & fast CDN!

How do we do this you may ask, well simple. GitLab provides us with 10 GB repository limit, we can use this to host our original data via GitLab Pages, then we serve it via Cloudflare, and we set a page rule for our CDN, so it always hit the cached version!

What is a CDN

According to Cloudflare, a CDN is a

CDN

A content delivery network (CDN) refers to a geographically distributed group of servers which work together to provide fast delivery of Internet content.

A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, javascript files, stylesheets, images, and videos. The popularity of CDN services continues to grow, and today the majority of web traffic is served through CDNs, including traffic from major sites like Facebook, Netflix, and Amazon.

A properly configured CDN may also help protect websites against some common malicious attacks, such as Distributed Denial of Service (DDOS) attacks.

Setup Requirements.

  • Domain. (you can use a subdomain that is on Cloudflare.)
  • GitLab account.

Setting up GitLab environment

Create your GitLab account if you don’t have one, go make it right now. Then create a repository with any name and the file .gitlab-ci.yml and a folder named public

Then fill the .gitlab-ci.yml with

 1image: alpine:latest
 2
 3pages:
 4  stage: deploy
 5  script:
 6    - echo 'Nothing to do...'
 7  artifacts:
 8    paths:
 9      - public
10    expire_in: 1h20min
11  rules:
12    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH

And your content on the public folder. Either image HTML file, anything.

Serve the content via GitLab Pages

After you’ve done the steps above, GitLab should auto generate a website.

Configuring Cloudflare

The next steps will be pretty straight forward. On GitLab, go to settings β†’ pages; then click on new domain. Add your domain there, and add it to Cloudflare by following the instructions. Next for optimization and 99% cache hit, set this page rule for your CDN domain

Nice

After that you’re good to go!

Thank you for reading, have a great day!