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

Azure Application Gateway与App Service Terraform部署问题咨询

问题1解答

该架构图属于标注错误,Azure平台本身不支持资源组嵌套逻辑。图中所谓的"子网下包含另一个RG"属于画图排版失误,实际要表达的含义是:归属于其他资源组的应用服务资源,被部署到了MainRG下VNET的对应子网中,并非真的存在资源组嵌套结构。

问题2解答

首先明确两个核心Azure资源逻辑:

  • Azure的虚拟网络、子网与资源组为松耦合关系,只要权限配置正确,其他资源组的资源完全可以接入归属于另一个资源组的VNET子网,不需要将App Service所属的整个资源组"部署"到子网内
  • 你当前使用的Standard S1层级的App Service Plan刚好支持VNET集成功能,可直接配置接入指定子网

改造步骤

1. 新增App Service专用委托子网

在network.tf中新增专门用于App Service VNET集成的子网,必须配置子网委托权限给App Service服务,否则无法正常接入:

resource "azurerm_subnet" "hri-prd-appservice-subnet" {
  name                 = "hri-prd-appservice-subnet"
  resource_group_name  = azurerm_resource_group.rg-hri-prd-eur-app-gate.name
  virtual_network_name = azurerm_virtual_network.hri-prd-VNET.name
  address_prefixes     = ["10.1.1.0/24"]

  delegation {
    name = "appservice-delegation"

    service_delegation {
      name    = "Microsoft.Web/serverFarms"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
    }
  }
}

2. 为App Service开启VNET集成

修改app.tf中的App Service资源配置,新增VNET集成块,直接跨资源组引用刚才创建的子网ID即可:

resource "azurerm_app_service" "hri-prd-eur-app-testing" {
  app_service_plan_id = azurerm_app_service_plan.ASP-hri-prd-app-service.id
  location            = var.app-service-loc
  name                = "hri-prd-eur-app-testing"
  resource_group_name = azurerm_resource_group.rg-hri-eur-app-service.name

  # 新增VNET集成配置
  vnet_config {
    subnet_id = azurerm_subnet.hri-prd-appservice-subnet.id
  }
}

3. 将App Service加入Application Gateway后端地址池

修改applicationGateway.tf中的后端地址池配置,关联App Service的默认域名,同时修改后端HTTP设置开启自动识别后端域名,避免访问时出现403错误:

# 后端地址池配置修改
backend_address_pool {
  name = local.backend_address_pool_name
  backend_addresses {
    fqdn = azurerm_app_service.hri-prd-eur-app-testing.default_site_hostname
  }
}

# 后端HTTP设置新增参数
backend_http_settings {
  name                  = local.http_setting_name
  cookie_based_affinity = "Disabled"
  path                  = "/path1/"
  port                  = 80
  protocol              = "Http"
  request_timeout       = 1
  # 新增以下参数
  pick_host_name_from_backend_address = true
}

内容的提问来源于stack exchange,提问作者Nayden Van

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.20 07:54:03