目录

Github自定义域名和域名解析设置

  • content {:toc}

域名注册

可以从网上搜索域名注册 关键词,进入域名注册提供商网站去注册自己想要的域名,看自己的情况选择购买合适价格的域名进行注册。 本人是在 注册的域名,现在注册需要实名认证之后才能成功解析域名。否则在网站上输入自己的域名无法访问到ip地址,即打不开网站。

域名解析

本人注册的域名解析的是解析至GitHub主机上。 是一个静态网页托管平台,你可以把你制作的HTML静态网页通过git工具上传至GitHub代码仓库。

在你GitHub上的某个项目上设置你的自定义域名

  1. 在GitHub上 , 导航至你的某个网页项目仓库 (GitHub Pages site’s repository)。
  2. https://help.github.com/assets/images/help/repository/repo-actions-settings.png在你的项目仓库下, 点击 **Settings **设置标签进入设置界面
  3. 在 “Custom domain,“下输入框中添加你的自定义域名(你之前购买的域名想要指向该项目作为网站,如:jaylin.top),之后点击 Save.按钮保存。 To check if your custom domain is supported, see “ .”
  4. 如果你设置了自定义域名之后可以强制为你的网站设置为 HTTPS 协议. For more information, see “ .”

在DNS提供商网站上设置DNS解析记录

如图,在阿里云上,我的DNS解析记录包括Apex记录,subdomain记录: /assets/images/dns_parse.png

Apex记录是指A记录是顶级域名解析设置,解析到的记录值是IP地址。eg:

记录类型记录值
A185.199.110.153 (这是github pages的IP地址)
subdomain记录是指CNAME子级域名记录解析设置,解析到github的网站域名。eg:
记录类型记录值
CNAMEusername.github.io(你的gitbug pages的域名)
  1. A记录是为了能够通过你注册的Apex顶级域名eg:jaylin.top在浏览器上输入访问时能解析指定访问到GitHub pages主机上。
  2. subdomain子级域名就是在顶级域名前加上前缀的域名eg: **shop.**jaylin.top。想要让某个子级域名也指向GitHub pages主机上需要设置的类型是CNAME类型,在GitHub上的对应代码仓库下,按照上述 的方法设置主机怎么显示这个子级域名代表的网页内容。

GitHub支持的域名类型

Supported custom domain typeExample domain
www subdomainwww.example.com
one apex domain & one www subdomainexample.com & www.example.com
apex domainexample.com
custom subdomainblog.example.com

补充说明如何申请你的github pages域名

  1. 在 上注册一个你的账号如:jaylin
  2. 创建一个代码仓库项目,名称是有要求的,前缀必须和你的注册的账号名称一样如:jaylin.gihub.io
  3. 然后这个代码仓库的项目名称:jaylin.gihub.io 就是你的GitHub pages的域名
  4. 通过git工具将你的网页代码上传这个项目仓库下,就可以通过http:// jaylin.gihub.io访问了。
  5. 如果你不满意这个仓库的域名,就可以自己注册一个自定义域名,步骤如上 。

自定义域名重定向至GitHub Pages site

The type of pages site you’re using determines how your site redirects custom domains.

Warning: If the URL for your GitHub Pages site contains a username or organization name that begins or ends in a dash, or contains consecutive dashes, then people browsing with Linux will receive a server error when they visit the site. To fix this, change your GitHub username to remove non-alphanumeric characters. For instructions on how to do this, see “ .”

Type of GitHub Pages sitePages default domain & host location on GitHubHow the page is redirectedExample custom domain
个人网站username.github.ioAutomatically redirected to the custom domain that has been set for ituser.example.com
企业orgname.github.ioAutomatically redirected to the custom domain that has been set for itorg.example.com
个人网站项目username.github.io/projectnameAutomatically redirected to a subdirectory of a User Pages site custom domain (user.example.com/projectname)project.example.com
企业网站项目orgname.github.io/projectnameAutomatically redirected to a subdirectory of an Organization Pages site custom domain (org.example.com/projectname)project.example.com
To learn more about the different GitHub Pages site types, including whether to use master or gh-pages as a publishing branch, see this .