0%

Configure Custom DNS with Hexo

While using Hexo to set up a github.io blog, the default domain name is [your-github-username].github.io. To use a custom DNS for your personal blog, Github requires you to create a file named CNAME in master branch of your repository. Since Hexo3, if you simply added the CNAME file manually it would be overwritten at deployment time. So you could use Hexo plugin: hexo-generator-cname.

Install

1
$ npm install hexo-generator-cname --save

Enable

Add hexo-generator-cname to plugins in _config.yml.

1
$ plugins: hexo-generator-cname

Configure domain name

Go to _config.yml file, and find the variable url. Configure your custom domain name like below.

1
url: http://[your-custom-domain-name]

When you run

1
$ hexo generate

again, a CNAME file containing your custom domain name configured just now in _config.yml will be created.

Then you need to login to your DNS provider and create a DNS CNAME record pointing hostname www to your-github-username.github.io. Here is a DNS provider I used before wanwang. It will take a couple hours to replicate default domain name with the custom one.