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

Azure应用网关Rewrite Rule Set无法删除:AZ CLI与PowerShell操作报错求助

解决Azure应用网关Rewrite Rule Set无法删除的问题

我帮你分析下这个问题:你遇到的是典型的资源引用残留导致的删除失败,错误提示里明确说了请求路由规则BasicRoutingRule还在引用要删除的CacheRuleSet,但因为你之前重建过规则集,可能引用关系没有自动更新,导致Azure在验证时出现“资源找不到”的冲突。下面是具体的解决步骤:

第一步:确认路由规则的引用关系

先验证BasicRoutingRule确实还保留着对CacheRuleSet的引用,用以下命令检查:

使用AZ CLI:

az network application-gateway request-routing-rule show \
  --resource-group <你的资源组名称> \
  --gateway-name <你的应用网关名称> \
  --name BasicRoutingRule \
  --query 'rewriteRuleSet'

使用PowerShell:

Get-AzApplicationGatewayRequestRoutingRule `
  -ResourceGroupName <你的资源组名称> `
  -ApplicationGatewayName <你的应用网关名称> `
  -Name BasicRoutingRule | Select-Object -ExpandProperty RewriteRuleSet

如果返回结果里包含CacheRuleSet的ID或名称,说明引用确实存在。

第二步:移除路由规则对Rewrite Rule Set的引用

接下来需要更新BasicRoutingRule,清除它对CacheRuleSet的关联:

使用AZ CLI:

az network application-gateway request-routing-rule update \
  --resource-group <你的资源组名称> \
  --gateway-name <你的应用网关名称> \
  --name BasicRoutingRule \
  --remove rewriteRuleSet

使用PowerShell:

# 获取应用网关对象
$gw = Get-AzApplicationGateway `
  -ResourceGroupName <你的资源组名称> `
  -Name <你的应用网关名称>

# 获取目标路由规则
$rule = Get-AzApplicationGatewayRequestRoutingRule `
  -ApplicationGateway $gw `
  -Name BasicRoutingRule

# 清除规则集引用
$rule.RewriteRuleSet = $null

# 保存配置变更
Set-AzApplicationGateway -ApplicationGateway $gw

第三步:再次尝试删除Rewrite Rule Set

完成引用清理后,执行删除命令:

使用AZ CLI:

az network application-gateway rewrite-rule set delete \
  --resource-group <你的资源组名称> \
  --gateway-name <你的应用网关名称> \
  --name CacheRuleSet

使用PowerShell:

# 删除规则集
Remove-AzApplicationGatewayRewriteRuleSet `
  -ResourceGroupName <你的资源组名称> `
  -ApplicationGatewayName <你的应用网关名称> `
  -Name CacheRuleSet

# 再次保存配置
Set-AzApplicationGateway -ApplicationGateway $gw

额外排查:如果仍然失败

要是执行以上步骤后还是删不掉,可能是应用网关存在配置缓存或异常状态,可以试试:

  • 重启应用网关,然后重复上述步骤
  • 检查是否有其他路由规则、监听端口引用了CacheRuleSet,用下面的命令批量排查:
az network application-gateway show --resource-group <你的资源组名称> --name <你的应用网关名称> --query 'requestRoutingRules[*].{Name:name, RewriteSet:rewriteRuleSet.id}'

补充说明:错误里的“资源未找到”其实是引用链断裂导致的——路由规则还指向你之前重建前的规则集,Azure找不到匹配的资源所以报错,核心就是先清理干净引用关系,再删除规则集。

内容的提问来源于stack exchange,提问作者Sisir Patnaik

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 20:52:38