首页 > 解决方案 > 将通配符域路由到 nginx 入口中的不同路径

问题描述

我如何实现与此类似的东西。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: /c/{word-maching-wildcard}

  name: some-route
  namespace: prod
spec:
  rules:
     - host: "*.example.com" # {hello}.example.com -> hello.example.com/hello
       http:
        paths:
         - backend:
            serviceName: svc
            servicePort: 8080
           path: /

有什么方法可以捕获子域中的匹配词,并在路由到上游服务之前将其附加到路径中。

标签: nginxkubernetes-ingressnginx-ingress

解决方案


来自官方文档:

spec.rules.host该字段不支持正则表达式和通配符 。必须使用完整的主机名。

请参阅:nginx-ingress-matching

但是我发现了类似的问题,建议编写自己的控制器,写出$http_host在适当proxy_pass或重定向行中使用的 nginx 配置。

阅读更多:通配符网址映射


推荐阅读