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

在DigitalOcean App Platform配置www转非www重定向遇验证错误

解决Ingress重定向规则配置报错问题

我尝试部署带有如下App Spec的应用,配置www到非www的Ingress重定向规则时遭遇报错:

第一个报错:
error validating app spec field "ingress.rules.rule.match.type": App Ingress routing match type is missing

添加path条目后,又出现新报错:
error validating app spec field "ingress.rules.rule.match": rule matching path prefix "/" already in use by rule with component: "website"

原App Spec内容:

alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
domains:
  - domain: domain.bla
    type: PRIMARY
    zone: domain.bla
  - domain: www.domain.bla
    type: ALIAS
    zone: domain.bla
features:
- buildpack-stack=ubuntu-22
ingress:
  rules:
  - component:
      name: website
    match:
      path:
        prefix: /
      authority:
        exact: "domain.bla"
  - redirect:
      authority: "domain.bla"
    match:
      authority:
        exact: "www.domain.bla"
      path:
        prefix: /
name: domain-bla
region: lon
services:
- http_port: 80
  image:
    # snip
  instance_count: 1
  instance_size_slug: basic-xxs
  name: website

解决方案

问题核心在于Ingress规则缺少明确的匹配类型定义,且重复使用了路径前缀/的匹配规则。调整后的配置如下:

alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
domains:
  - domain: domain.bla
    type: PRIMARY
    zone: domain.bla
  - domain: www.domain.bla
    type: ALIAS
    zone: domain.bla
features:
- buildpack-stack=ubuntu-22
ingress:
  rules:
  - component:
      name: website
    match:
      type: path_prefix
      path: /
      authority:
        exact: "domain.bla"
  - redirect:
      authority: "domain.bla"
      type: permanent_redirect
    match:
      type: authority_exact
      authority: "www.domain.bla"
name: domain-bla
region: lon
services:
- http_port: 80
  image:
    # snip
  instance_count: 1
  instance_size_slug: basic-xxs
  name: website

修改说明

  • 为每个match块添加type字段:第一个规则用path_prefix明确匹配路径前缀,第二个规则用authority_exact仅匹配域名,避免路径规则重复冲突。
  • 重定向规则添加type: permanent_redirect(可根据需求改为temporary_redirect),明确重定向类型。
  • 移除重定向规则中的path配置,仅通过域名匹配完成www到非www的跳转,所有子路径会自动继承该重定向逻辑。

内容的提问来源于stack exchange,提问作者Jasper van den Bosch

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 14:25:02