Have you built a beautiful website? Are you looking to host it for free with a custom domain? Look no further.
This article will explain how to get your website up using two great free tools: Github Pages and Cloudflare. Before we get started, lets go over some of the basics:
Cloudflare is a CDN – a content distribution network. It mirrors your website on its servers all over the world. That means it’s faster for anyone who wants to access it, no matter where they are. As a bonus, it also protects you against people who might want to overload your site with automated bots trying to visit it and drain your bandwidth (DDOS attacks).
You can read more about how they describe themselves here.
There are several reasons to use Cloudflare. It’s free. It has a simple DNS manager that lets you set up mail and subdomains. It’s got built-in HTTPS domain management. It automatically minifies static assets of your website, speeds up how people all over the world accessing your website, and protects against downtime. You can see their panel of options to set right here:
About GitHub Pages:
GitHub is best known for being a code repository, and GitHub Pages was originally designed as a way for open-source projects to host pages about themselves. Since its release, it’s grown into a highly versatile platform for hosting content in a production setting. It’s reliable, robust, fast, and great for serving most kinds of corporate and personal static sites. Their own description puts it best: “GitHub Pages is a static site hosting service. It is designed to host your personal, organization, or project pages directly from a GitHub repository.”
See more here.
What is a static site?
What do we need to start?
Before beginning, make sure you:
Step 1: Deploy your static website using Github Pages.
We should have a Github repository and a deployment environment using Github Pages. We deploy using Github Pages when we make a push to “gh-pages” branch.
Step 2: Insert your custom domain in Github repository settings
Select the option “settings” from the repository’s navbar. It’s the last option. When you are in “settings”, scroll to Github Pages area and insert your custom domain and click on the “save” button.
Step 3: Setup your custom domain on Cloudflare
Log in to your Cloudflare account and insert your custom domain to scan DNS Records.
After you click on “Scan DNS Records” button, there will be a progress bar. You should click on “continue button” when the progress bar will finish. Then insert the necessary DNS and CNAME. We will get this structure:
The A and CNAME records are the two common ways to map a hostname to one or more IP address.
The A record points a name to a specific IP, when the IP are known and stable.. In our case, the name yourdomain.com to point to the server 188.8.131.52
The CNAME record points a name to another name, instead of an IP. The CNAME source represents an alias for the target name and inherits its entire resolution chain. In our case, we use Github Pages and we set www as a CNAME of astephannie.github.io
In this step, we are setting two “A Record DNS”, it’s necessary because we are getting the communication between Cloudflare and Github Pages. From now, all requests to yourdomain.com will be routed to the static website on Github. Click on “continue” button to go to the next step.
Step 4: Select the Cloudflare plan
Select the Cloudflare plan you want. In our case, we select “Free Website” and click on the “continue” button.
Step 5: Update the Nameservers on your domain dashboard
Copy the Nameservers from Cloudflare and paste them on your Domain dashboard.
For this example, we have a domain of godaddy.com. We need to access to our domain and change the Nameservers.
You will have this result in pending status at the beginning:
At the end, the status will change:
Step 6: Setup Minification of the website assets
There are some other options to consider in Cloudflare to setup. We did the necessary steps to have our website live on the domain we setup. You can check caching and page rules to continue exploring the options of Cloudflare and verify how powerful can Cloudflare be.
Step 7: You’re done!
Your website is live. You can make changes directly in Github on the gh-pages branch, and they’ll appear directly on your website.
Annie is a frontend software engineer at Crowdbotics.
November 16, 2017