Setting Up a Blog with Github Pages, Route 53, and CloudFront
Tools
- AWS Route 53 (DNS management)
- AWS CloudFront (CDN)
- AWS Certificate Manager (SSL certificate provisioning)
- Github Pages (Static site hosting)
- Jekyll (Static site generator)
$$
Cost-wise this blog is free to maintain. Registering your custom domain will cost you around $12 annually, and then Route 53 and CloudFront will likely fall in the free tier depending on your traffic. Github Pages is free.
Hosting a site on Github Pages
Github pages allows you to host websites through static files (you’ll need an index.html at least in the root of the repo), or a Jekyll template which Github Pages will auto-build.
- Make a new repository on Github named
your-account.github.io
, this part is important because it will be your user lever repository, and will be accessible atyour-account.github.io
- In the settings of your repo, turn on Github Pages. You don’t need to tell it you’re using a custom domain here, things will work fine the way it defaults
- You can either pick a theme right from the suggestions it gives you or try to figure that part on your own. I use the default Jekyll theme
minima
Registering your domain
While Github hosts my static site for free at nimaeskandary.github.io
already, I wanted to buy nimaeskandary.com
before another Nima Eskandary got any ideas.
- Log into the AWS management console
- Search for the service
Route 53
- On the left sidebar, under Domains, go to
Registered Domains
- Register the domain you want, it took about 10 minutes for my registration to go through. The exact domain I registered was
nimaeskandary.com
Provisioning your SSL cert
It is becoming more and more commonplace to block non HTTPS traffic.
- In the AWS management console, set your top right data center to
US EAST (N. Virginia)
. This is important because CloudFront only uses certs stored there, and AWS will store your cert in the data center you are connected to. - Search for the service
Certificate Manager
- You’ll want to add two domain names,
base-domain.com
, in my case this wasnimaeskandary.com
, and*.base-domain.com
, the wild card is so you can use the cert for any records in your zone, e.g.www.base-domain.com
,blog.base-domain.com
- When asked, verify that you own the domain through the DNS option, it is very easy and all it will have you do is make a CNAME record in Route 53
Setting up CloudFront
While you could make a CNAME record that routes www.you-domain.com
to your-account.github.io
and be done with it, using CloudFront offers a few advantages:
-
It will allow
base-domain.com
, to also point to the right place, because your root zone cannot be a CNAME, but AWS lets you have it point to a CloudFront distribution through a specialalias
record -
It will allow you to also serve your SSL cert, without it people couldn’t use HTTPS on your custom domain
- In the AWS management console, search for CloudFront
- Set up a new “Web” distribution
- For the
origin domain name
, put the Github pages domain, in my case it wasnimaeskandary.github.io
- For
origin path
don’t put anything - For
viewer protocol policy
I personallyredirect HTTP to HTTPS
- For
allowed HTTP methods
doGET, HEAD, OPTIONS
- I change the
default TTL
to 0 because I want people to see my updates right away - In
price class
I only use US, Canada, and Europe, really any option is fine - For
alternate domain names (CNAMEs)
you’ll want any address you think you’ll use. I put downnimaeskandary.com
,www.nimaeskandary.com
, andblog.nimaeskandary.com
- Choose the Custom SSL cert we made earlier
- And that’s it, it should take about 15 minutes for it to spin up once you click the finish button
Creating your DNS records
- In the AWS management console, search for Route 53
- Create an alias record, with no added record name, this will just make the record named
your-domain.com
- Have the alias record point to your CloudFront domain name, this can be found in the CloudFront management page for the distribution you just made, and will be something like
dn542fesffj83.cloudfront.net
- Optionally, you can also create a CNAME record named
www.
, that points toyour-domain.com
, that way bothwww.your-domain.com
andyour-domain.com
work. I also added ablog.
record as well
All done, hope this was helpful. If this gets outdated feel free to shoot me an email