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

如何通过AGIC配置Azure应用网关实现短名称到FQDN的重定向

解决AGIC下短域名到FQDN的重定向方案

核心思路

通过配置双Ingress规则(对应短域名与FQDN),结合AGIC专属注解实现重定向,确保配置会被AGIC同步到应用网关,不会被后续覆盖。

正确的YAML配置

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: contoso-ingress
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
    # 短域名重定向核心配置
    appgw.ingress.kubernetes.io/redirect-target: "https://contoso.com"
    appgw.ingress.kubernetes.io/redirect-type: "Permanent" # 可选Temporary(302)或Permanent(301)
    appgw.ingress.kubernetes.io/redirect-include-path: "false" # 无需携带原路径时设置为false
spec:
  rules:
  # 短域名规则:触发重定向逻辑
  - host: contoso
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: dummy-service # 需配置一个占位用的空服务
            port:
              number: 80
  # FQDN规则:指向实际业务服务
  - host: contoso.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: your-actual-service
            port:
              number: 80

必要的辅助配置

由于Ingress规则必须关联后端服务,需创建一个空的ClusterIP服务作为占位:

apiVersion: v1
kind: Service
metadata:
  name: dummy-service
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80

关键说明

  • 单独使用appgw.ingress.kubernetes.io/redirect-target不会生效,必须配合redirect-type指定重定向类型,AGIC才会生成对应的应用网关规则。
  • 若需路径级精准重定向,可将重定向注解移至paths层级,而非全局注解。
  • 目标地址需完整指定协议(http://或https://),避免应用网关生成无效规则。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 14:54:59