You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Azure Frontdoor批量上传、导入导出规则集及批量导入重定向URL?

Azure Frontdoor 批量操作实操指南

1. 批量上传规则集

Azure Portal暂不支持直接批量上传规则集,需借助Azure CLI或PowerShell结合ARM模板实现:

  • 步骤1:导出现有规则集的ARM模板,可通过Portal的"导出模板"功能,或执行CLI命令:
    az afd rule-set show --resource-group <资源组名> --profile-name <Frontdoor配置文件名> --rule-set-name <规则集名> --output json > rule-set-template.json
    
  • 步骤2:修改模板中的properties.rules数组,批量添加/编辑规则的name、priority、matchConditions、actions等核心配置
  • 步骤3:部署修改后的模板完成批量上传:
    az deployment group create --resource-group <资源组名> --template-file rule-set-template.json
    

2. 批量导入/导出规则集

导出规则集

  • 方法1(Portal):进入目标Frontdoor实例的"规则集"页面,选中规则集后点击顶部"导出模板",下载包含完整配置的JSON文件
  • 方法2(CLI):直接导出规则列表:
    az afd rule-list --resource-group <资源组名> --profile-name <Frontdoor配置文件名> --rule-set-name <规则集名> --output json > rules-export.json
    

导入规则集

  • 方法1(ARM模板):基于导出的模板或自定义规则JSON,执行批量部署命令(同批量上传的步骤3)
  • 方法2(PowerShell):读取规则配置JSON,循环调用New-AzFrontDoorCdnRule命令逐个创建规则(需注意规则优先级不重复)

3. 通过CSV/Excel一次性导入重定向URL配置

需通过脚本将CSV/Excel配置转换为Frontdoor规则,步骤如下:

  • 步骤1:准备CSV文件,包含字段:源URL路径、目标URL、重定向类型(301/302)、规则优先级
  • 步骤2:编写PowerShell脚本读取CSV并批量创建重定向规则:
    $rules = Import-Csv -Path "redirect-rules.csv"
    foreach ($rule in $rules) {
        New-AzFrontDoorCdnRule `
            -ResourceGroupName "<资源组名>" `
            -ProfileName "<Frontdoor配置文件名>" `
            -RuleSetName "<规则集名>" `
            -Name "redirect-rule-$($rule.规则优先级)" `
            -Priority $rule.规则优先级 `
            -MatchCondition @{
                MatchVariable = "RequestUri"
                Operator = "Equal"
                MatchValue = $rule.源URL路径
            } `
            -Action @{
                Name = "UrlRedirect"
                Parameters = @{
                    RedirectType = $rule.重定向类型
                    DestinationProtocol = "Https"
                    CustomHostname = ($rule.目标URL -split '/')[2]
                    CustomPath = $rule.目标URL.Substring($rule.目标URL.IndexOf('/'))
                }
            }
    }
    
  • 步骤3:运行脚本完成导入,可通过Portal或CLI验证规则生效状态

内容的提问来源于stack exchange,提问作者Vidhyardhi Gorrepati

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 23:51:17