Github Pages 自定义域名

Github Pages 自定义域名


12年买域名的时候8块钱。买了5年。现在域名到期变贵了。。要35元/年, /(ㄒoㄒ)/~~

观众:35块都嫌贵,你这个臭屌丝。。。

O(∩_∩)O 好吧,不贵不贵。


现在有个github pages. 官网可以支持 hexo 和 jeckly(不会拼).我写了自己的build.js。没用它们。

今天在万网把域名blog.yanggaofei.cn指向了bryanyang.github.io,配置如下:

记录类型主机记录解析线路记录值MX优先级TTL
CNAMEblog默认bryanyang.github.io--10分钟

结果访问http://blog.yanggaofei.cn出现大大的404:

去官网看了下,有文档详细描述该如何配置custom domain


1.Pick your custom domain and register it with a DNS provider. A DNS provider is a company that allows users to buy and register a unique domain name and connect that name to an IP (Internet Protocol) address by pointing your domain name to an IP address or a different domain name. A DNS provider is also called a domain registrar or DNS host.


2.Set up your pages site repository by creating and committing a CNAME file that contains your custom domain.


3.Set up your custom domain with your DNS provider. Our guides outline how to set up your pages custom domain with your DNS provider depending on the type of custom domain you have:


  • Setting up an apex domain such as example.com
  • Setting up a www subdomain such as www.example.com
  • Setting up an apex domain and www subdomain such as example.com and www.example.com
  • Setting up a custom subdomain such as blog.example.com

第2步,需要在repository下面增加CNAME文件:Adding your custom domain to a CNAME file


1.去到自己的 Pages site repository.

2.在"Branches" 菜单, 切换到你的 repository's Pages 分支:

  • For User and Organization Pages sites, the Pages branch is master.
  • For Project Pages sites, the Pages branch is gh-pages.

    3.在文件列表中, 点击 New file.

    4.文件名, 填写 CNAME (全部大写!).

    5.在文件内容中, 添加一行来指定你的域名,不要填写 https://http://. 例如, 用www.example.com, 而不是 https://www.example.com. 注意只能添加一行纪录。

    6.在页面底部,填入commit message上传。

    7.(直接传到master就行,该条可略过)Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.

    8.(略)Click Propose new file.



OK。如果操作正确的话,就可以在Setting里看到新的domain了。


一个线上例子:


最后,如果你的域名指向没改的。记得去DNS服务商网站去改。见页面上方我的配置。




附录,本文md文件:

 
 
  1. ## Github Pages 自定义域名
  2. ------
  3. 12年买域名的时候8块钱。买了5年。现在域名到期变贵了。。要35元/年, /(ㄒoㄒ)/~~
  4. 观众:35块都嫌贵,你这个臭屌丝。。。
  5. O(∩_∩)O 好吧,不贵不贵。
  6.  
  7. 现在有个github pages. 官网可以支持 hexo jeckly(不会拼).我写了自己的build.js。没用它们。
  8. 今天在万网把域名`blog.yanggaofei.cn`指向了`bryanyang.github.io`,配置如下:
  9. |------------------------------------
  10. 记录类型|主机记录|解析线路|记录值|MX优先级| TTL
  11. CNAME|blog|默认|bryanyang.github.io|--|10分钟
  12. ------------------------------------|
  13. 结果访问`http://blog.yanggaofei.cn`出现大大的404:
  14. ![404](https://segmentfault.com/img/bVq6HR)
  15. 去官网看了下,有文档详细描述该如何配置**custom domain**
  16. [Setting up a custom domain](https://help.github.com/articles/quick-start-setting-up-a-custom-domain/)
  17. >
  18. 1.Pick your custom domain and register it with a DNS provider. A DNS provider is a company that allows users to buy and register a unique domain name and connect that name to an IP (Internet Protocol) address by pointing your domain name to an IP address or a different domain name. A DNS provider is also called a domain registrar or DNS host.
  19. 2.Set up your pages site repository by creating and committing a CNAME file that contains your custom domain.
  20. 3.Set up your custom domain with your DNS provider. Our guides outline how to set up your pages custom domain with your DNS provider depending on the type of custom domain you have:
  21. * Setting up an apex domain such as example.com
  22. * Setting up a www subdomain such as www.example.com
  23. * Setting up an apex domain and www subdomain such as example.com and www.example.com
  24. * Setting up a custom subdomain such as blog.example.com
  25.  
  26. ### 第二步,需要在repository下面增加`CNAME`文件:[Adding your custom domain to a CNAME file](https://help.github.com/articles/setting-up-your-pages-site-repository/)
  27. >
  28. 1.去到自己的 Pages site repository.
  29. 2."Branches" 菜单, 切换到你的 repository's Pages 分支:
  30. * For User and Organization Pages sites, the Pages branch is master.
  31. * For Project Pages sites, the Pages branch is gh-pages.
  32. 3.在文件列表中, 点击 **New file**.
  33. ![The New file buttonAbove the file list, click New file](https://help.github.com/assets/images/help/repository/create_new_file.png)
  34. 4.文件名, 填写 *CNAME* (全部大写!).
  35. 5.在文件内容中, 添加一行来指定你的域名,不要填写 `https://` 或 `http://`. 例如, 用 `www.example.com`, 而不是 `https://www.example.com`. 注意只能添加一行纪录。
  36. 6.在页面底部,填入commit message上传。
  37. ![img](https://help.github.com/assets/images/help/repository/write-commit-message-quick-pull.png)
  38. 7.(直接传到master就行,该条可略过)Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is master, you should choose to create a new branch for your commit and then create a pull request.
  39. ![img](https://help.github.com/assets/images/help/repository/choose-commit-branch.png)
  40. 8.(略)Click Propose new file.
  41. ![img](https://help.github.com/assets/images/help/repository/new-file-commit-button.png)
  42.  
  43.  
  44.  
  45. OK。如果操作正确的话,就可以在**Setting**里看到新的domain了。
  46. ![img](https://help.github.com/assets/images/help/repository/repo-actions-settings.png)
  47. ![img](https://help.github.com/assets/images/help/settings/pages-section.png)
  48.  
  49. 一个线上例子:
  50. [a CNAME file](https://github.com/muan/muan.github.com/blob/master/CNAME)
  51. -------
  52. 最后,如果你的域名指向没改的。记得去DNS服务商网站去改。见页面上方我的配置。
  53.  

通过build.js之后,生成了 json 数据文件,F12见控制台网络请求。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值