Hosting Hugo Blog on Github Pages

I have wrote about my previous setup for Hugo blog here that was using the AWS S3 bucket and CloudFront as static site. Although it is decent setup, there are some complexities that can be simplified.

  • First, that setup will cost you the S3 bandwidth charges. Storage charges are not much because of the small size but if traffic on your blog is increasing it will increase the AWS bill.
  • Deployment is bit complex. If you are not aware how AWS S3 and CloudFront works, you will have a hard fixing/upgrading it.

So to solve these problems, I found a better solution, use Github pages to host your blog with a custom domain. Github pages are free and serve the site from the Github repo. This way there is no cost involved for the hosting. Hugo has simple official support documentation to run it on Github pages. Deployment is very simple, just push the changes to the Github repo.

I have dumped the fancy io domain hemc.io to simple .com domain hemc4.com which costs 1/4 of the io domain.

It is better the keep the whole setup simple for maintainability. Simpler the setup, less friction it will generate to do the actual work.

Hugo Site on Github Pages

Hugo has official documentation for setting up site with Github pages. This is concise and self sufficient for the setup. I just followed the approach with the 2 repos setup.

  • Private repo to Hugo files
  • Public repo for generated static site files

I have slightly modified the script for pushing the changes to private repo.

Internet is full of the more complex setup with Github actions and different CI/CD tools, but I prefer this simple setup for deploy. After every new post creation just run the script.

./deploy.sh

Custom domain for Github Pages

Custom domain setup requires changes on the DNS file of your domain and the Github bucket repo settings.

Setting up the domain DNS entries

godaddy_dns_setup.png

Domain requires 4 A entries and 1 CNAME entry in the DNS file.

Setting up Github repo

github_custom_domain.png

if you face any problem while setting up custom domain Github has detailed guide here


References:

Hugo official doc for Github pages hosting

Github official docs for custom domains

Setting up a custom domain to point to Github pages

Github custom domain troubleshooting

Load Comments?