通过优先流量功能,您可以指定 Cloudflare One Appliance(前称 Magic WAN Connector)应优先处理哪些应用程序。列表外的应用程序流量会排在优先流量之后。
与分流流量类似,优先流量也通过检查 DNS 请求工作。
在 Cloudflare One Appliance 中添加或移除优先流量(Prioritized traffic)应用程序之前,您需要一份账户级应用程序列表。该列表包含两类应用程序:
- Cloudflare 托管应用程序(Cloudflare-managed applications) — Cloudflare 内置的已识别应用程序目录。这些应用程序已存在于您的账户中,无需创建。在分配应用程序流量时直接选择即可。
- 自定义应用程序(Custom applications) — 您通过 hostname(主机名)、IP subnet(IP 子网) 和/或 source subnet(源子网) 定义的应用程序。您可以直接从仪表板或通过 Create an account app 端点创建、编辑和删除自定义应用程序。
- 转到 Connectors(连接器) 页面。
- 转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
- 选择您要配置的 Cloudflare One Appliance > Edit(编辑)。
- 选择 Traffic Steering(流量引导)。
- 在 Prioritized traffic(优先流量) 中,选择 Assign application traffic(分配应用程序流量)。
- 在 Custom applications(自定义应用程序) 中,选择 Add(添加) 以创建新的自定义应用程序,并输入:
- Name(名称) — 应用程序的显示名称。
- Category(类别) — 可选的分组标签,例如
Productivity或Video conferencing。 - Hostnames(主机名)、IP subnets(IP 子网) 或 Source subnets(源子网) 中至少一项 — 用于识别此应用程序的流量。主机名必须是有效的 FQDN(例如
auth.example.com)。IP 子网和源子网必须是有效的 IPv4 CIDR(例如10.0.0.0/24)。单个地址需要/32后缀。尚不支持 IPv6。
- 选择 Add application(添加应用程序)。
- 要更改或移除现有自定义应用程序,请在 Custom applications(自定义应用程序) 表格中选择其旁边的 三个点,然后选择 Edit(编辑) 或 Delete(删除)。
发送 POST 请求以在您的账户中创建自定义应用程序。以下示例使用全部三个可选匹配条件:
Required API token permissions
At least one of the following token permissions is required:Magic WAN WriteMagic Transit Write
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/apps" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Example application",
"type": "Productivity",
"hostnames": [
"auth.example.com"
],
"ip_subnets": [
"192.0.2.0/24"
],
"source_subnets": [
"10.0.0.0/24"
]
}'{
"result": {
"account_app_id": "eb09v665c0784618a3e4ba9809258fd4",
"name": "Example application",
"type": "Productivity",
"hostnames": ["auth.example.com"],
"ip_subnets": ["192.0.2.0/24"],
"source_subnets": ["10.0.0.0/24"]
},
"success": true,
"errors": [],
"messages": []
}现在可以将这个新应用程序添加到 Cloudflare One Appliance 的优先流量列表。
需要为每个现有站点配置优先流量应用程序,因为这是一项按站点设置的配置。
- 转到 Connectors(连接器) 页面。
-
转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
-
选择您要配置的 Cloudflare One Appliance > Edit(编辑)。
-
选择 Traffic Steering。
-
在 Prioritized traffic(优先流量) 中,选择 Assign application traffic(分配应用程序流量)。
-
从 Custom applications(自定义应用程序) 或 Cloudflare-managed applications(Cloudflare 托管应用程序) 中选择一个或多个应优先处理的应用程序。您也可以使用搜索框,或选择 Add(添加) 以在不离开此面板的情况下定义新的自定义应用程序 — 请参阅 创建、编辑或删除自定义应用程序。
-
选择 Save(保存)。
Connector 现在会优先处理所选应用程序的流量。
-
发送
GET请求,列出与账户关联的应用程序。
At least one of the following token permissions is required:Required API token permissions
Magic WAN WriteMagic WAN ReadMagic Transit ReadMagic Transit Write
List Appsbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/apps" \ --request GET \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{ "result": [ { "managed_app_id": "<APP_ID>", "name": "<APP_NAME>", "type": "File Sharing", "hostnames": [ "<app_name.com>", "<app-name.info>" ] } ] }记下要添加的每个应用程序的
"managed_app_id"值。 -
发送
POST请求,将新应用程序添加到优先流量策略。
At least one of the following token permissions is required:Required API token permissions
Magic WAN WriteMagic Transit Write
Create a new App Configbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/app_configs" \ --request POST \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ --json '{ "managed_app_id": "<MANAGED_APP_ID>", "breakout": true }'{ "result": { "account_app_id": "<APP_ID>", "name": "<APP_NAME>", "type": "<BREAKOUT_OR_PRIORITY>" }, "success": true, "errors": [], "messages": [] }
使用 Source subnets(源子网) 定义的自定义应用程序也可以用这种方式标记为优先。完整的基于源的匹配条件请参阅 基于源的突围。
- 转到 Connectors(连接器) 页面。
-
转到 Appliances(设备) 选项卡 > Profiles(配置文件)。
-
选择要配置的 Appliance > Edit。
-
选择 Traffic Steering。
-
在 Prioritized traffic 中,找到要删除的应用程序,选择其旁边的 three dots,再选择 Remove application traffic。
-
(可选)如果应用程序列表有多页,可以使用搜索框快速查找目标应用程序。
需要从每个现有站点删除优先流量应用程序,因为这是一项按站点设置的配置。
-
发送
GET请求,列出与站点关联的应用程序。
At least one of the following token permissions is required:Required API token permissions
Magic WAN WriteMagic WAN ReadMagic Transit ReadMagic Transit Write
List App Configsbash curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/sites/$SITE_ID/app_configs" \ --request GET \ --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{ "result": [ { "id": "<APP_ID>", "site_id": "<SITE_ID>", "managed_app_id": "<APP_NAME>", "breakout": true } ] }记下要删除的应用程序的
"id"值。 -
发送
DELETE请求,从优先流量策略删除应用程序。curl "https://api.cloudflare.com/client/v4/accounts/%7Baccount_id%7D/magic/sites/%7Bsite_id%7D/app_configs/%7Bid%7D" \ --request DELETE{ "result": { "id": "<APP_ID>", "site_id": "<SITE_ID>", "managed_app_id": "<APP_NAME>", "breakout": true }, "success": true, "errors": [], "messages": [] }