> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/docs-site/custom-domain.md).

# 设置自定义域名

{% hint style="info" %}
此功能适用于 [高级和终极站点方案](https://www.gitbook.com/pricing).
{% endhint %}

{% hint style="warning" %}
本页展示如何配置自定义域名和子域名。如果你想配置自定义子目录（例如 `example.com/docs`），请参阅 [设置自定义子目录](/docs/documentation/zh/docs-site/custom-domain/setting-a-custom-subdirectory.md) 页面中。
{% endhint %}

默认情况下，你的网站可通过一个 `[subdomain].gitbook.io` 域名访问。

你可以通过设置自定义域名来进行个性化配置，这意味着你的受众可以通过你选定的域名访问你的文档。

{% stepper %}
{% step %}

#### 选择子域名

选择子域名时，你可以使用 `www` 或自定义子域名。一些常用的子域名有：

* `docs.example.com`
* `help.example.com`
* `developers.example.com`
  {% endstep %}

{% step %}

#### 开始设置自定义域名

前往你想要设置自定义域名的网站。点击 **设置，** 然后选择 **设置自定义域名。**

在这里，你会看到一个窗口，可以输入你在第一步中选择的自定义域名。输入后点击 **下一步。**
{% endstep %}

{% step %}

#### 配置 DNS

在这一步，你会看到一个包含三个字段的窗口： **类型、名称、目标。**

这些就是你在 DNS 服务商处设置自定义域名时要使用的详细信息。这需要在 *GitBook 之外* 进行，也就是在你用于域名的服务商处完成。

复制以下内容： **名称** 和 **目标** 字段，并将其用于你的 DNS 服务商。每个服务商都不同，所以如果不确定，请直接向他们确认如何添加这条记录。你应该能够从你服务商提供的列表中选择 **在** 记录类型。

添加记录后，变更可能需要一些时间才能生效。我们建议 **至少等待 1 小时** 再进行下一步。准备好后，点击 **下一步** 。
{% endstep %}

{% step %}

#### 完成设置

在添加记录并等待其生效后，就可以正式上线了！GitBook 将验证域名和你添加的记录，并自动为你的域名配置 SSL 证书。

完成后，你会收到通知，并可以点击 **完成**。如果需要，你也可以关闭窗口；当我们这边的流程完成后，我们会向你发送通知。
{% endstep %}
{% endstepper %}

### 故障排查

设置自定义域名有时可能会遇到障碍。下面我们列出此过程中常见的问题，并为每个问题提供详细解决方案。

<details>

<summary>SSL 错误：在配置你的 SSL 证书时发生了错误。</summary>

当为你的组织、组或版块设置了自定义域名时，我们会在后台为你配置 SSL 证书，以便你的文档能通过 HTTPS 安全加载。\
\
当你设置自定义域名时，这会自动完成——你无需购买或配置 SSL 证书。

偶尔在此阶段会发生错误，通常是因为自定义域名的 CNAME 记录尚未生效。

在这种情况下，我们建议如下：

1. 检查你的 CNAME 记录是否设置正确。\
   请查看我们关于配置 DNS 的页面，它会帮助你完成此操作。\
   如果 CNAME 记录不正确，我们将无法配置 SSL 证书并完成自定义域名设置。
2. 请 ***至少等待一小时*** 再从配置 CNAME 记录到完成自定义域名设置之间进行操作。
3. 确认 CNAME 是否已生效。你可以尝试使用第三方 DNS 查询工具，例如 [WhatsMyDNS](https://www.whatsmydns.net/)，来查看服务器认为你的正确 CNAME 记录是什么。
4. 如果你正在使用 Cloudflare，请确认该记录没有启用代理 [，如下所述](https://developers.cloudflare.com/fundamentals/setup/manage-domains/pause-cloudflare/#disable-proxy-on-dns-records).

</details>

<details>

<summary>域名已连接错误：你的子域名已为其他内容配置。</summary>

分配给某个网站的自定义域名必须是唯一的。尝试在多个位置使用同一个自定义域名会导致错误。

如果发生这种情况，你可以点击错误消息中的链接，查看该自定义域名已连接到的内容。这有助于你决定下一步该怎么做。

不过，也有可能你无法访问这些内容——如果是这种情况，请联系支持团队，他们可以帮助你规划下一步。

不过，这个错误的解决方案始终只有两种：

1. 选择另一个自定义域名；或者
2. 将自定义域名与它当前连接的内容解除关联，然后重新连接到新内容。

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/docs-site/custom-domain.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
