Hugo Blogging - Applying a Custom Domain

This post is one of several in the “Hugo Blogging” series. If you haven’t, read the introduction to get started.

Prerequisites

Setup

Google Domain

  1. Log in to Google Domains.
  2. In your domain dashboard, select the “DNS” tab on the left.
  3. Under “Name servers”, set “Use the Google Domain name servers”.
  4. Under “Custom resource records”, add the following:
    • “A” record
      • Name: @
      • IPv4 addresses:
        • 185.199.108.153
        • 185.199.109.153
        • 185.199.110.153
        • 185.199.111.153
    • “CNAME” record
      • Name: www
      • IPv4 address:
        • <YOUR_GITHUB_PAGES_URL>

This is what my resource table looks like:

NameTypeTTLIPv4 Address
@A1h185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
wwwCNAME1handrewmjordan.github.io

Note: it may take up to 48 hours before changes are applied.


GitHub

  1. Log in to GitHub.
  2. Select your repository. Go the repository “Settings”.
  3. Choose “Options” on the left. Find the GitHub Pages settings.
  4. Set “Custom domain” to your domain. In my case, andtech.me.
  5. Set the branch to gh-pages.
  6. Set the folder to /(root).
  7. Enable “Enforce HTTPS”.

The “Enforce HTTPS” option may not be available immediately.


Hugo Project

  1. Edit config.toml.

    • Change the value of baseURL to your custom URL.

      • Example: baseURL = "https://andtech.me"
    • Make sure your project is configure to publish to public.

      • Example: publishDir = "public"
  2. Create a new file at static/CNAME. The only contents of this file should be your domain.

For example, my static/CNAME looks like this:

andtech.me
  1. Commit and push these changes.

References


245 Words

2021-02-13 02:26 +0000