Use custom domain to your blog built on Hexo
If you want use your own domain name instead of the one (xxx.github.io
) given by github, the following steps should be taken.
Get your git page’s ip
1
2ping xxx.github.io
//change the xxx on your own
The returnXXX.XXX.XXX.XXX
is the ip you need.- Configure DNS Setting
The operation for different provider varies, you should figure it out on your own. - Create CNAME file
Change to hexo directory, create a CNAME file under source directory. Add your custom domain to the file Things get done via the following commands
1
hexo clean && hexo g && hexo d
After this, when you enter the
xxx.github.io
into your browser, it will automatically redirect to your own domain. And if you enter your own domain, the browser will show you your blog content.
How to reset to original domain given by github
If you want to reset the domain, you can achieve it by doing following steps
Change directory to your repo, and clean it
1
hexo clean
Edit your CNAME file, leave it blank or just delete it
Finished via commands
1
hexo g && hexo d
Then you could check out whether it works by entering your original url(xxx.github.io) into browser. If it doesn’t redirect to your custom domain and it shows contents instead of 404 page, it means it works.
- One more thing: if you don’t want your custom domain link to your blog, you could just configure the DNS and remove the relative rule.
That’s all for this tutorial.