如何为 GitHub 页面设置 Google 域名

2025-06-07

如何为 GitHub 页面设置 Google 域名

谷歌域名和 GitHub 页面

简介

Github Pages 设置起来很简单,但要使用 Google Domains 绑定自定义域名,可能会遇到一些问题。以下 4 个步骤教你如何操作。

先决条件

步骤 1/4:让 gitHub 页面知道你的自定义域名

  • 前往你的 GitHub 存储库设置页面
    GitHub 设置

  • 在“设置”>“GitHub 页面”>“自定义域名”中添加自定义域名
    GitHub 设置 Github 页面

步骤 2/4:让你的自定义域名(trentyang.com)指向你的 GitHub 页面

  • 转到您的 Google 域名注册页面,选择您的域名
    Google 域名注册

  • 转到 DNS > 自定义资源记录
    DNS 自定义资源记录

  • 添加如下截图所示的记录。注意,您需要使用“+”按钮添加更多 URL。 以下是截图中的 IP 列表:
    一项记录

    • 185.199.111.153
    • 185.199.110.153
    • 185.199.109.153
    • 185.199.108.153

如果这些已经过时,您也可以在github上找到最新的

  • 要确认您的 DNS 记录是否设置正确,请使用 dig 命令查找您的域名“控制台

$ dig trentyang.com +noall +answer
trentyang.com. 3600 IN A 185.199.111.153
trentyang.com. 3600 IN A 185.199.110.153
trentyang.com. 3600 IN A 185.199.109.153
trentyang.com. 3600 IN A 185.199.108.153



  • Once the above is successful, your custom domain should work correctly. Go to your domain and take a look!

STEP 3/4: Let your www sub-domain (www.trentyang.com) point to your github pages

  • Add the following CNAME record
    CNAME record

  • You can use the following dig command to confirm that your setup is correct

    Enter fullscreen mode Exit fullscreen mode

$ dig www.trentyang.com +nostats +nocomments +nocmd
www.trentyang.com. IN A
www.trentyang.com. 1263 IN CNAME chun-yang.github.io.

Enter fullscreen mode Exit fullscreen mode




步骤 4/4:(可选但强烈推荐)为你的 GitHub 页面启用 HTTPS

  • 转到您的 github 存储库设置页面,在设置> GitHub 页面> 自定义域下删除您的自定义域并保存。GitHub 设置 Github 页面
  • 然后将其添加回来并再次保存。
  • 现在您应该能够选中“强制 HTTPS”复选框并保护您的网站!

如果您喜欢阅读,请访问我的博客https://trentyang.com/how-to-setup-google-domain-for-github-pages/

文章来源:https://dev.to/trentyang/how-to-setup-google-domain-for-github-pages-1p58
PREV
使用 JS 进行函数式编程
NEXT
GitHub 上排名前 33 的 JavaScript 项目(2018 年 8 月)第 32 个项目太搞笑了😂,而且它居然出现在这个榜单上