共用方式為

在 Azure Front Door 上配置规则集

Applies to: ✔️ Front Door Standard ✔️ Front Door Premium

本文介绍如何使用 Azure 门户创建规则集和第一组规则。 你还将了解如何从“规则集”页面或 Front Door 管理器将规则集关联到路由。

Prerequisites

在 Azure 门户中配置规则集

  1. 转到 Azure Front Door 配置文件。 Select Rule sets under Settings in the left side menu pane. Select + Add, then give the rule set a name.

  2. 若要创建第一个规则,请指定规则名称。 然后,选择“+ 添加条件”或“+ 添加操作”来定义规则。 一个规则最多可添加 10 个条件和 5 个操作。 本示例使用服务器变量将“设备类型”追加到来自“移动”设备类型的请求的响应头。 For more information, see match conditions and actions.

    规则集配置页的屏幕截图。

    Note

    • 若要从规则中删除某个条件或操作,请使用相应条件或操作右侧的垃圾桶图标。
    • 若要创建适用于所有传入流量的规则,请不要指定任何条件。
    • 若要在满足某个特定规则后停止对其余规则进行评估,请选中“停止评估剩余规则”。 如果选中此选项,则无论满足何种匹配条件,都不会执行该规则集中的所有剩余规则以及与路由关联的所有剩余规则集。
    • 规则引擎中的所有路径都区分大小写。
    • Header names should adhere to RFC 7230.
  3. 你可以使用箭头按钮向上或向下移动规则,以在规则集中设置规则的优先级。 列表按升序排列,因此首先列出的是优先级最高的规则。

    规则集优先级的屏幕截图。

    Tip

    若要验证将更改传播到 Azure Front Door 的时间,请根据以下示例在规则中创建自定义响应头。 添加响应头 _X-<RuleName>-Version_,并在每次更新规则时更改版本值。

    自定义版本标头规则的屏幕截图。 更新更改后,请转到 URL 以确认正在调用的规则版本:自定义标头版本输出的屏幕截图。

  4. Once you create all the rules you need, select Save to complete the creation of your rule set.

  5. 现在,可以将规则集与路由关联,使其生效。 你可以在“规则集”页面关联规则集,也可以从 Front Door 管理器执行此操作。

    “规则集”页:

    1. 在“规则集”页面中,选择“未关联”链接,将规则集关联到路由。

    2. 然后在“关联路由”页面中,选择要与该规则集关联的终结点和路由。

      创建路由页的屏幕截图。

    3. Select Next to change the rule set order if you have multiple rule sets for the selected route. 规则集将按所列顺序处理。 你可以通过选择规则集并使用页面顶部的按钮来更改顺序。 Select Associate to complete the route association.

      Note

      在此页中,只能将一个规则集与一个路由关联。 若要将规则集与另一个路由关联,请使用 Front Door 管理器。

    4. 现在,规则集已与路由关联。 你可以查看响应头,确认是否已添加设备类型。

      与路由关联的规则的屏幕截图。

Front Door 管理器:

  1. In the Front Door manager, select the ... next to the route you want to configure, then select Edit route.

    屏幕截图显示在 Front Door 管理器中编辑路由。

  2. On the Update route page, under Rules, select the rule sets you want to associate with the route from the dropdown. 你还可以更改规则集的顺序。

    “更新路由”页中的规则集的屏幕截图。

  3. Select Update to save the route configuration.

删除规则集

如果不再需要 Azure Front Door 配置文件中的某个规则集,请执行以下步骤将其移除:

  1. Navigate to the Rule set page under Settings.

  2. Select the ... next to the rule set you want to remove and select Disassociate from all routes.

  3. After the rule set is disassociated, select the ... again. Select Delete and then confirm by selecting Yes.

  4. 重复上述步骤,以移除 Azure Front Door 配置文件中的其他规则集(如有)。

Next steps

了解如何使用规则集添加安全性标头