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

Bicep部署静态Web应用遇段长度错误,如何修复域名配置?

问题

我有一个用于部署静态Web应用的Bicep文件:

@description('rootCustomDomainName')
param rootCustomDomainName string = 'https://xyz.contoso.com'

resource staticWebApp 'Microsoft.Web/staticSites@2022-03-01' = {
  name: 'my-ui'
  location: location
  sku: {
    name: 'Free'
    tier: 'Free'
  }
  properties: {
    allowConfigFileUpdates: true
    branch: branch
    buildProperties: {
      appLocation: 'UI/web-app'
      skipGithubActionWorkflowGeneration: true
    }
    enterpriseGradeCdnStatus: 'Disabled'
    provider: 'DevOps'
    repositoryUrl: repositoryUrl
    stagingEnvironmentPolicy: 'Disabled'
  }
}

resource rootCustomDomain 'Microsoft.Web/staticSites/customDomains@2022-03-01' = {
  parent: staticWebApp
  name: rootCustomDomainName
  properties: {}
}

部署该文件时,出现以下错误:

[error]Deployment template validation failed: 'The template resource my-ui/https://xyz.contoso.com for type 'Microsoft.Web/staticSites/customDomains' at line '1' and column '2294' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name.

请问我遗漏了什么?该如何修复?

原因与修复方案
  • 错误原因:自定义域名参数包含了https://前缀,而Azure静态Web应用的自定义域名资源名称仅需纯域名(不含协议前缀)。带前缀的字符串作为子资源名称时,会导致资源ID格式错误(出现斜杠分割的多余段),触发模板验证失败。

  • 修复步骤:

    1. 修改参数rootCustomDomainName的默认值,移除https://前缀,仅保留纯域名:
      @description('rootCustomDomainName')
      param rootCustomDomainName string = 'xyz.contoso.com'
      
    2. 确保传递该参数时,仅传入纯域名(不含任何协议前缀)。

修改后,自定义域名资源的名称会变为my-ui/xyz.contoso.com,符合Azure资源ID的格式要求,可通过模板验证并完成部署。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 07:52:55