跳转到内容
搜索文档

开始使用

最后更新 查看 MarkdownAgent 设置

Spectrum 在所有付费计划中均可用。Pro 和 Business 仅支持特定的协议,而 Enterprise 支持所有基于 TCP 和 UDP 的流量。有关更多配置细节,请参阅配置选项

要创建 Spectrum 应用程序,您可以使用 IP 地址、CNAME 记录或负载均衡器。无论您使用哪种方法,都可以通过仪表板或 API 创建应用程序。

Spectrum 请求和响应正文中的某些字段需要 Enterprise 计划。有关更多详细信息,请参阅按计划设置页面。

使用 IP 地址创建 Spectrum 应用程序

要使用 IP 地址创建 Spectrum 应用程序,Cloudflare 通常会从 Cloudflare 的 IP 池中为您分配一个任意 IP 到您的应用程序。如果您想使用自己的 IP 地址,可以使用 自带 IP (BYOIP),也可以使用静态 IP。在后两种情况下,您需要通过 API 创建 Spectrum 应用程序,因为这些功能在仪表板中不可用。使用 API 时,字段 origin_direct 将 IP 地址作为输入。

通过仪表板添加您的应用程序

  1. 在 Cloudflare 仪表板中,转到 Spectrum 页面。

    Go to Spectrum ↗
  2. 选择 Create an Application(创建应用程序)。如果这是您第一次使用 Spectrum,将出现 Create an Application(创建应用程序) 模式窗口。

  3. 选择您的 Application type(应用程序类型)

  4. Domain(域) 下,输入将使用 Spectrum 的域。

  5. Edge Port(边缘端口) 下,输入 Cloudflare 应该为您的应用程序使用的端口。

  6. Origin(源站) 下,输入您应用程序的源站 IP 和端口。

  7. 如果您的应用程序需要客户端 IP 并且支持 Proxy Protocol,请启用 Proxy Protocol(代理协议)。代理协议是像 Cloudflare 这样的代理向源站应用程序发送客户端 IP 的一种方法。

  8. 选择 Add(添加)

通过 API 添加您的应用程序

下面是一个 curl 示例以及发布到 API 的关联数据。

API 示例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"protocol": "tcp/22",
		"dns": {
				"type": "CNAME",
				"name": "ssh.example.com"
		},
		"origin_direct": [
				"tcp://192.0.2.1:22"
		],
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "full",
		"edge_ips": {
				"type": "dynamic",
				"connectivity": "all"
		},
		"traffic_type": "direct",
		"argo_smart_routing": true
	}'

示例数据:

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"id": "ea95132c15732412d22c1476fa83f27a",
		"protocol": "tcp/22",
		"dns": {
			"type": "CNAME",
			"name": "ssh.example.com"
		},
		"origin_direct": ["tcp://192.0.2.1:22"],
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "full",
		"edge_ips": {
			"type": "dynamic",
			"connectivity": "all"
		},
		"traffic_type": "direct",
		"argo_smart_routing": true,
		"created_on": "2014-01-02T02:20:00Z",
		"modified_on": "2014-01-02T02:20:00Z"
	}
}

使用 CNAME 记录创建 Spectrum 应用程序

要使用 CNAME 记录创建 Spectrum 应用程序,您需要在 Cloudflare 托管区域上创建一个指向源站主机名的 CNAME 记录。这是解析到您的主机名源站所必需的。有关更多信息,请参阅创建 DNS 记录。当使用 CNAME 作为源站时,请注意 Cloudflare 必须是该区域的权威。使用 API 时,origin_dns 字段将 CNAME 记录作为输入。

通过仪表板添加您的应用程序

  1. 在 Cloudflare 仪表板中,转到 Spectrum 页面。

    Go to Spectrum ↗
  2. 选择 Create an Application(创建应用程序)。如果这是您第一次使用 Spectrum,将出现 Create an Application(创建应用程序) 模式窗口。

  3. 选择您的 Application type(应用程序类型)

  4. Domain(域) 下,输入将使用 Spectrum 的域。

  5. Edge Port(边缘端口) 下,输入 Cloudflare 应该为您的应用程序使用的端口。

  6. 源站下,输入您的 CNAME 记录名称。

  7. 选择 Add(添加)

通过 API 添加您的应用程序

下面是一个 curl 示例以及发布到 API 的关联数据。

API 示例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"dns": {
				"type": "CNAME",
				"name": "spectrum-cname.example.com"
		},
		"ip_firewall": false,
		"protocol": "tcp/22",
		"proxy_protocol": "off",
		"tls": "off",
		"origin_dns": {
				"name": "cname-to-origin.example.com",
				"ttl": 1200
		},
		"origin_port": 22
	}'

示例数据:

{
	"dns": {
		"type": "CNAME",
		"name": "spectrum-cname.example.com"
	},
	"ip_firewall": false,
	"protocol": "tcp/22",
	"proxy_protocol": "off",
	"tls": "off",
	"origin_dns": {
		"name": "cname-to-origin.example.com",
		"ttl": 1200
	},
	"origin_port": 22
}

使用负载均衡器创建 Spectrum 应用程序

要使用负载均衡器创建 Spectrum 应用程序,您需要从仪表板或通过 API 生成负载均衡器。有关更多详细信息,请参阅 负载均衡文档

通过仪表板添加您的应用程序

  1. 在 Cloudflare 仪表板中,转到 Spectrum 页面。

    Go to Spectrum ↗
  2. 选择 Create an Application(创建应用程序)。如果是您首次使用 Spectrum,将显示 Create an Application(创建应用程序) 弹出框。

  3. 选择您的**应用程序类型**。

  4. Domain(域) 下,输入将使用 Spectrum 的域。

  5. Edge Port(边缘端口) 下,输入 Cloudflare 应为您的应用程序使用的端口。

  6. Origin(源) 下,选择 Load Balancer(负载均衡器)

  7. 从下拉菜单中选择您要使用的负载均衡器。已禁用的负载均衡器不会显示在 Load Balancer(负载均衡器) 菜单中。

  8. 选择 Add(添加)

通过 API 添加您的应用程序

下面是一个 curl 示例以及发布到 API 的相关数据。

API 示例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"dns": {
				"type": "CNAME",
				"name": "spectrum-cname.example.com"
		},
		"ip_firewall": false,
		"protocol": "tcp/22",
		"proxy_protocol": "off",
		"tls": "off",
		"origin_dns": {
				"name": "cname-to-origin.example.com",
				"ttl": 1200
		},
		"origin_port": 22
	}'

示例数据:

{
  "dns": {
    "type": "CNAME",
    "name": "spectrum-cname.example.com"
  },
  "ip_firewall": false,
  "protocol": "tcp/22",
  "proxy_protocol": "off",
  "tls": "off",
  "origin_dns": {
    "name": "cname-to-origin.example.com",
    "ttl": 1200
  },
  "origin_port": 22
}

使用虚拟网络源站创建 Spectrum 应用程序

要将 TCP 或 UDP 流量代理到专用网络上的源站,请将 Cloudflare Tunnel 虚拟网络附加到 Spectrum 应用程序。Spectrum 通过与该虚拟网络关联的连接器 (Cloudflare Tunnel 或 Cloudflare WAN 连接) 路由流量。这提供了一种替代先前在专用源站前面放置负载均衡器模式的方法。

虚拟网络源站仅支持 TCP 和 UDP 应用程序。源站必须是在指定的虚拟网络内可路由的单个专用 IP。不支持端口范围、主机名源站 (origin_dns) 以及 origin_direct 中的多个地址。目前不支持代理协议,因此 proxy_protocol 必须设置为 off。有关验证错误的详细信息,请参阅错误代码

有关虚拟网络的入门指南,请参阅虚拟网络

开始之前

在创建 Spectrum 应用程序之前,设置虚拟网络和覆盖您的源站 IP 的路由:

  • 按照管理虚拟网络创建虚拟网络以及承载该虚拟网络的 Cloudflare Tunnel。
  • 按照连接 IP/CIDR将覆盖您的源站的专用 IP 的路由附加到隧道。

如果将 Cloudflare WAN(以前称为 Magic WAN)作为连接器,请参阅 Cloudflare WAN 入门以设置隧道端点和路由。

通过仪表板添加您的应用程序

  1. 在 Cloudflare 仪表板中,转到 Spectrum 页面。

    Go to Spectrum ↗
  2. 选择 Create an Application(创建应用程序)

  3. Application type(应用程序类型) 下,选择 TCPUDP

  4. Domain(域) 下,输入将使用 Spectrum 的域。

  5. Edge Port(边缘端口) 下,输入 Cloudflare 应该为您的应用程序使用的端口。

  6. Origin(源站) 下,选择 Virtual Network(虚拟网络)

  7. Virtual Network(虚拟网络) 下,选择包含您的源站的虚拟网络。

  8. IP 下,输入您的源站的专用 IP 地址。

  9. Port(端口) 下,输入单个端口(不支持端口范围)。

  10. 选择 Add(添加)

通过 API 添加您的应用程序

下面是一个 curl 示例以及发布到 API 的关联数据。

API 示例:

Required API token permissions

At least one of the following token permissions is required:
  • Zone Settings Write
Create Spectrum application using a name for the originbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/spectrum/apps" \
	--request POST \
	--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
	--json '{
		"protocol": "tcp/22",
		"dns": {
				"type": "CNAME",
				"name": "ssh.example.com"
		},
		"origin_direct": [
				"tcp://10.0.0.5:22"
		],
		"virtual_network_id": "f70ff985-a4ef-4643-bbbc-4a0ed4fc8415",
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "off",
		"edge_ips": {
				"type": "dynamic",
				"connectivity": "all"
		},
		"traffic_type": "direct"
	}'

origin_direct 设置为您的源站的专用 IP,将 virtual_network_id 设置为 IP 在其内部可路由的虚拟网络的 ID。您可以使用列出虚拟网络端点为您的账户列出虚拟网络。

示例数据:

{
	"success": true,
	"errors": [],
	"messages": [],
	"result": {
		"id": "ea95132c15732412d22c1476fa83f27a",
		"protocol": "tcp/22",
		"dns": {
			"type": "CNAME",
			"name": "ssh.example.com"
		},
		"origin_direct": ["tcp://10.0.0.5:22"],
		"virtual_network_id": "f70ff985-a4ef-4643-bbbc-4a0ed4fc8415",
		"proxy_protocol": "off",
		"ip_firewall": true,
		"tls": "off",
		"edge_ips": {
			"type": "dynamic",
			"connectivity": "all"
		},
		"traffic_type": "direct",
		"created_on": "2014-01-02T02:20:00Z",
		"modified_on": "2014-01-02T02:20:00Z"
	}
}

查看流量

您现在可以通过 Cloudflare 代理流量,而无需进行其他配置。当您通过 Cloudflare 传输流量时,您将在仪表板中的 Spectrum 下看到最后一分钟的流量。

如果您有任何反馈,请告诉我们

这篇文档对您有帮助吗?