Host a static web using Github pages, custom domain and https
This post is about how to host a static web site on Github pages, using a custom domain and HTTPS.
First a static web site prepared to be deployed on any host.
Note: remember, a static web site is not using php, pythom, asp etc is only html,css and js. Dynamic content will not work
Second, a Github account to create a new public repository. This repository will be special because is designed to have one per free account and are limited.
The repository needs to have a special name, your username. Using my username as a example, u915 ,you need to create a new repository called u915.
You will be warned about using the same name as your username and it will create a special repository like:
u915/u915 is a special repository. Its README.md will appear on your public profile! Send feedback
Once the site is created you can place any test plain file to probe the site, something like a default index.html
Clone the repository and test the site
git clone https://github.com/u915/u915.git echo "it´s works" > index.html git add --all git commit -m "testing" git push
Now there are a basic index.html prepared to be accesed via internet.
Check the repository configuration:
https://github.com/u915/u915 > settings > Github Pages
Point the master branch or the branch you used to push the default index.html a similar message to this can be readed:
Your Github Pages site is currently being built from the master branch.
By default all the content is deployed on the special url:
Accesing the url will display the index.html
Third, a custom domain, example: u915.net.
Instead of the Github page url supplied, I want to use the site with a custom domain.
To do that is necessary to point the domain to the Github pages url.
So, when a custom domain u915.net is resolved will be pointed to u915.github.io
To do that, DNS must be configured pointing to the Github servers.
The Github urls on the day of this post have been written are:
22.214.171.124 126.96.36.199 188.8.131.52 184.108.40.206
On the domain provider add the Github urls with DNS A records and add a CNAME www pointing to the Github pages url, https://u915.github.io
This is my configuration:
Type | Host | Value | TTL --- | --- | --- | --- A record | @ | 220.127.116.11 | auto A record | @ | 18.104.22.168 | auto A record | @ | 22.214.171.124 | auto A record | @ | 126.96.36.199 | auto CNAME | www | u915.github.io | auto
When changes are confirmed, it is normal that the changes are not inmmediate specially if it is a new domain, the changes will have effect when the DNS are propagated.
There are some sites like: dnschecker.org where you can check the DNS propagation.
Or can be confirmed using dig
dig +noall +answer u915.net u915.net. 1799 IN A 188.8.131.52 u915.net. 1799 IN A 184.108.40.206 u915.net. 1799 IN A 220.127.116.11 u915.net. 1799 IN A 18.104.22.168
Check the configuration and enable HTTPS
Add the custom domain using the repository configuration and Confirm that the custom domain can reach Github pages on the configuration page. Inside you can enforce to use HTTPS requests, Github will generate a special cert for the repository in a 3 phase action.
If there are any error or warnings will be appear on the same place (the configuration panel), if all is ok you will be rewarded with the green tick and the site will be accesible using the custom domain and https.
Thanks for reading.
The content of this post is a personal writeup of the process done, all is based of the Github documentation.