> For the complete documentation index, see [llms.txt](https://www.axisnow.io/zh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.axisnow.io/zh/docs/multi-edge/getting-started/unlock-cloudflare/how-it-works.md). Agents can also search and read this documentation through its [MCP server](https://www.axisnow.io/zh/docs/~gitbook/mcp).

# 工作原理

一键解锁 Cloudflare 的工作原理：Cloudflare for SaaS 实现 CNAME 接入多家 CDN，用到 Custom Hostname 和 Custom Origin Server，以及回源 SNI、源站证书与 Full (strict) 的注意事项

一键解锁没有搬动任何配置，只是借助 [Cloudflare for SaaS](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/) 在您的 zone 里为域名多开了一个可以被 CNAME 指向的入口。解锁后的解析与请求路径如下：

<figure><img src="https://3062891322-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKDgGNU6JXG7cqYCk2aCz%2Fuploads%2Fgit-blob-eebd7c95463c3a623d90e64d1d8a0b68bbecaf4b%2Funlock-cloudflare-how-it-works.png?alt=media" alt="解锁后的 DNS 解析与请求路径：域名 CNAME 到服务 CNAME，解析到 Cloudflare 的接入地址，之后添加的其他边缘提供商与它并列；访客的请求命中 zone 内与域名同名的 Custom Hostname，回源时 Host 不变，SNI 变为 cfsaas- 开头的域名"><figcaption></figcaption></figure>

* **DNS 解析**：域名 CNAME 到 AxisNow 的服务 CNAME，由 AxisNow 调度。此时服务里只有 Cloudflare 一家，解析结果是 Cloudflare 的接入地址；之后添加的边缘提供商与它并列，由路由规则决定解析到哪一家。
* **请求路径**：访客的请求照常到达 Cloudflare，命中 zone 内与域名同名的 **Custom Hostname**，按这个 zone 的配置处理后回源。
* **唯一的变化**：回源的 TLS 握手使用一个 `cfsaas-` 开头的域名作为 SNI，Host 不变。

本页先说明这个方案的优势，再按请求路径依次解释三个环节：[入口](#why-cloudflare-for-saas)、[回源](#why-cfsaas-sni)和[源站](#origin-requirements)。

## 方案的优势 <a href="#advantages" id="advantages"></a>

* **不受套餐限制，不用迁移 NS**。Cloudflare 官方的多 CDN 接入方式是 [Partial（CNAME）Setup](https://developers.cloudflare.com/dns/zone-setups/partial-setup/)，只对 Business 及以上套餐开放，还要把 zone 的权威 DNS 迁出 Cloudflare，影响 zone 下的全部记录，风险高。一键解锁在免费套餐上即可完成，NS 和 DNS 托管都不变。
* **原有配置完整保留**。全部操作都在域名原来的 zone 内进行，WAF、缓存规则、Workers 和源站配置照常生效，不需要迁移或重建。
* **只改一条 DNS 记录**。切换时只有域名自己的记录从 Proxied 改为一条 CNAME，zone 下的其他记录不动。
* **先检查，再切换**。切换前，AxisNow 检测 zone 和记录，并按解锁后的回源方式实测源站；准备阶段发现站点变差会自动回滚。在您点击 **切换** 之前，访客的访问路径没有任何变化。
* **随时一键恢复**。切换后点击 **恢复记录**，域名的记录即恢复为原来的 Proxied 记录。

## 入口：借助 Cloudflare for SaaS <a href="#why-cloudflare-for-saas" id="why-cloudflare-for-saas"></a>

**Full Setup 没有可调度的入口**。免费和 Pro 套餐的域名只能以 Full Setup 接入 Cloudflare：DNS 托管在 Cloudflare，Proxied 记录直接解析到 Cloudflare 的地址。这条路径上没有可供第三方 CNAME 指向的入口，其他边缘提供商无从参与。把记录改为 DNS only 再 CNAME 出去也不行：Cloudflare 不再代理这个域名，zone 上的 WAF、缓存规则、Workers 全部失效。

**Cloudflare for SaaS 提供了入口**。它原本供 SaaS 平台使用：平台在自己的 zone 里为客户域名创建 Custom Hostname，客户域名 CNAME 过来，Cloudflare 便按该 zone 的配置为它服务。这项能力免费套餐即可使用，提供的正是 Full Setup 所缺的入口。

**直接把当前 zone 当作 SaaS zone**。Custom Hostname 的流量按它所属 zone 的配置处理。向导不另建 zone，而是在域名所在的 zone（示例中为 `axisnow.io`）内创建与域名同名的 Custom Hostname，所以原有配置对新路径同样生效，API Token 也只需要这一个 zone 的权限。

## 回源：使用 Custom Origin Server <a href="#why-cfsaas-sni" id="why-cfsaas-sni"></a>

Custom Hostname 有两种回源方式，Cloudflare 对它们使用的 SNI 有[明确规定](https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/start/advanced-settings/custom-origin/)：

<table data-search="false"><thead><tr><th width="230">回源方式</th><th width="230">回源地址</th><th>回源 Host</th><th>回源 SNI</th></tr></thead><tbody><tr><td>Fallback Origin（默认）</td><td>zone 的 Fallback Origin</td><td>业务域名</td><td>业务域名</td></tr><tr><td>Custom Origin Server</td><td>为该 Custom Hostname 指定的记录</td><td>业务域名</td><td>指定记录的域名</td></tr></tbody></table>

### 为什么不能用默认的 Fallback Origin <a href="#why-not-fallback-origin" id="why-not-fallback-origin"></a>

默认方式的 SNI 不变，看起来更合适，但它在同一个 zone 内行不通。

Fallback Origin 是为域名不在 SaaS zone 里的情形设计的。一键解锁把域名自己的 zone 当作 SaaS zone，切换之后 `demo.axisnow.io` 在 zone 里仍有一条记录，即指向服务 CNAME 的那条 CNAME。实测表明，Cloudflare 此时按这条记录查找回源，不走 Fallback Origin。而这条记录经服务 CNAME 又解析回 Cloudflare 自己的地址，请求得到 Error 1000 或长时间无响应。

### 为什么使用 Custom Origin Server <a href="#why-custom-origin-server" id="why-custom-origin-server"></a>

Custom Origin Server 为 Custom Hostname 明确指定回源记录，不受上面那条记录的影响。向导在 zone 内创建一条 Proxied 的 `cfsaas-` 记录，内容与域名原记录相同，并把它指定为 Custom Hostname 的 Custom Origin Server。

* **代价是回源 SNI 改变**。按上表，Host 仍是业务域名，SNI 变为这条记录的域名，例如 `cfsaas-7889e721.axisnow.io`。
* **SNI 无法改回业务域名**。Cloudflare 提供的两种办法（Custom Hostname 的 SNI 改写、Origin Rules 的 SNI 覆盖）都只对 Enterprise 套餐开放。
* **这条记录同时是 zone 的 Fallback Origin**，即准备步骤中 **Fallback Origin** 一行。它是 Cloudflare for SaaS 生效的前提，但回源并不依赖它。

## 源站：接受 cfsaas- 域名 <a href="#origin-requirements" id="origin-requirements"></a>

源站是否需要调整，取决于 zone 的 SSL/TLS 加密模式：

<table data-search="false"><thead><tr><th width="170">SSL/TLS 加密</th><th width="250">Cloudflare 回源时的行为</th><th>对源站的要求</th></tr></thead><tbody><tr><td>Off / Flexible</td><td>使用 HTTP 回源，没有 TLS 握手</td><td>无</td></tr><tr><td>Full</td><td>使用 HTTPS 回源，不校验源站证书</td><td>接受以 <code>cfsaas-</code> 域名为 SNI 的 TLS 握手</td></tr><tr><td>Full (strict)</td><td>使用 HTTPS 回源，并校验源站证书</td><td>接受握手，且源站证书覆盖 <code>cfsaas-</code> 域名</td></tr></tbody></table>

向导在检查阶段按解锁后的回源方式实测源站，并针对下面几种情况给出提示，见[源站预检](https://www.axisnow.io/zh/docs/multi-edge/getting-started/unlock-cloudflare.md#origin-precheck)。

### 接受握手 <a href="#origin-accepts-cfsaas-sni" id="origin-accepts-cfsaas-sni"></a>

Full 和 Full (strict) 下，源站收到的 SNI 是它没见过的 `cfsaas-` 域名：

* **自建源站**：nginx、Apache 等通常对未知 SNI 返回默认证书，握手成功，不受影响。
* **托管平台**：Vercel、Render 等只接受已添加的域名，会拒绝握手，Cloudflare 返回 525。需要先把 `cfsaas-` 域名添加到平台的项目域名。

### 源站证书为什么推荐泛域名 <a href="#why-wildcard-origin-certificate" id="why-wildcard-origin-certificate"></a>

Full (strict) 下，Cloudflare 要求源站证书由公共 CA 或 Cloudflare Origin CA 签发、未过期，并且覆盖回源使用的 SNI。解锁前 SNI 是业务域名，只包含 `demo.axisnow.io` 的证书可以通过校验；解锁后 SNI 变为 `cfsaas-` 域名，这张证书不再覆盖它，Cloudflare 返回 526。

泛域名证书 `*.axisnow.io` 同时覆盖业务域名和 `cfsaas-` 域名：

* **以后也不用再处理**。同一 zone 下新增的域名各有自己的 `cfsaas-` 域名，泛域名证书都能覆盖。
* **Cloudflare Origin CA 证书默认就是泛域名**。在 Cloudflare 控制台的 **SSL/TLS › Origin Server** 可以免费签发，默认包含 zone 根域名和一级泛域名，签发后安装到源站。

### 什么时候需要把 Full (strict) 改为 Full <a href="#why-switch-to-full" id="why-switch-to-full"></a>

源站证书无法更换为覆盖 `cfsaas-` 域名的证书时，可以把 zone 的 SSL/TLS 加密从 Full (strict) 改为 Full。改后 Cloudflare 仍以 HTTPS 回源，但不再校验源站证书，证书是否覆盖 `cfsaas-` 域名不再影响回源。

{% hint style="warning" %}
SSL/TLS 加密模式对整个 zone 生效，改为 Full 后 Cloudflare 不再校验这个 zone 下所有域名的源站证书。建议优先更换为泛域名证书，保留 Full (strict)。AxisNow 不会替您修改这项设置。
{% endhint %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.axisnow.io/zh/docs/multi-edge/getting-started/unlock-cloudflare/how-it-works.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
