简体   繁体   中英

routing wildcard domain to different paths in nginx ingress

how do I achieve something similar to this.

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: /

Is there any way to capture the matching word in the subdomain and append it in the path before routing to the upstream service.

From the official doc:

Regular expressions and wild cards are not supported in the spec.rules.host field. Full hostnames must be used.

See: nginx-ingress-matching .

However I have found similar problem which advice to write your own controller that writes out an nginx config that uses $http_host in the appropriate proxy_pass or redirect lines.

Read more: wildcard-url-mapping .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM