Skip to main content

custom domain name in github pages with hugo

·313 words·2 mins

Custom github domain name configuration with hugo #

I decided I wanted to setup a custom handler for an endpoint for hugo to github pages rather than the https://bowdena.github.io/ephemera.reify.au that I was used to and instead resolving to https://ephemera.reify.au.

I thought that this would be an easy CNAME entry into my DNS host but it turned out to be a little messier than that.

Firstly, I followed this guide Managing a custom domain for your GitHub Pages site. At the bottom, there was this handy dandy table that I thought I could just follow and enter the CNAME type of entry for:

ScenarioDNS record typeDNS record nameDNS record value(s)
Apex domain
(example.com)
A@185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
Apex domain
(example.com)
AAAA@2606:50c0:8000::153
2606:50c0:8001::153
2606:50c0:8002::153
2606:50c0:8003::153
Apex domain
(example.com)
ALIAS or ANAME@USERNAME.github.io or
ORGANIZATION.github.io
Subdomain
(ww​w.example.com,
blog.example.com)
CNAMESUBDOMAIN.example.com.USERNAME.github.io or
ORGANIZATION.github.io

I went to the repo -> pages and update the custom domain section so that it looked like this:

custom domain
Time Waster! I spent some cycles, and it took me longer than I’d like to admit that to realise I needed to do a redeploy in order for this to do anything

Once I had finally redeployed, I was getting errors on the page, it would render without any of the css or js stylesheets. The developer console showed the error the page loaded over HTTPS but requested HTTP

I thought that it was related to my hugo.toml file, but in the end I came across this post that mentioned that github has a different deployment than the toml configuration. Sure enough, in the default .github/workflows/hugo.yml file I found the stanza:

1
2
3
4
  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}

I went to the github workflow and found that sure enough, the site was being deployed to http rather than https

workflow
failing deploy

The solution was to tick the Enforce HTTPS box in the github pages location and the redeploy

tick https
solving the problem