Today I migrated my personal blog from the default *.github.io to a custom domain. The process is not as smooth as I expected, so here I write down what I did right and wrong.

Prerequisite

A personal using Hexo is already set up and being successfully deployed on *.github.io

Buy a domain

I researched Google Domains and GoDaddy. GoDaddy offers a lower first-year price, but for the following year it is getting pricy, while Google Domain offers a flat annual price. I bought with Google since I plan to keep my domain for a long time.

GoDaddy
Google Domains

Deploy to custom domain (on GitHub repo)

  1. Modify _config.yml file; change url to the new domain

  2. Add CNAME file in source directory

    • Caveat: Github tutorial will ask you to first create a CNAME file under root directory, and that pull the commit to your local repo. However, doing this will cause you to lose the CNAME file in your next Hexo deployment because Hexo will DELETE the CNAME file. A workaround is to put the CNAME file in the source directory.

Add subdomain (on hosting provider)

  1. Get your git pages’IP

    1
    2
    ping xxx.github.io
    // change xxx to your own

    The return XXX.XXX.XXX.XXX is the ip you need.

  2. Configurate DNS seeting in your domain host

Note: some tutorial will ask you to create a CNAME record instead. The main difference between the A record and CNAME record is that the A record maps a name to one or more IP addresses when IP are known and stable, while the CNAME record maps a name too another name. It should only be used when there are no other records on that name.

Redeploy

1
hexo clean && hexo g && hexo d

Reference

  1. https://alexzl5.github.io/use-custom-domain-with-hexo/
  2. https://xiaoyuliu.github.io/2018/03/28/how-to-sync-hexo-blog/