将特定的子目录重定向到Ingress中的新URL

时间:2018-12-27 13:49:21

标签: kubernetes-ingress

我需要将特定的URL重定向到新的URL。 我可以使用此代码重定向根域,但不适用于子目录,如testdomain.com/specific-url

(...)
"Mounts": [
        {
            "Type": "bind",
            "Source": "/host_mnt/c/my_local_dir",
            "Destination": "/www",
            "Mode": "",
            "RW": true,
            "Propagation": "rprivate"
        }
(...)

1 个答案:

答案 0 :(得分:1)

尝试使用以下建议的方法here。 并复制粘贴以供将来使用:

我的建议是,在负担得起的情况下使用NGINX Plus Ingress Controller注释功能。

您可以找到official example here

示例:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: cafe-ingress
  annotations:
    nginx.org/rewrites: "serviceName=tea-svc rewrite=/;serviceName=coffee-svc rewrite=/beans/"
spec:
  rules:
  - host: cafe.example.com
    http:
      paths:
      - path: /tea/
        backend:
          serviceName: tea-svc
          servicePort: 80
      - path: /coffee/
        backend:
          serviceName: coffee-svc
          servicePort: 80

下面是如何重写对tea-svc的请求的URI(请注意,将/tea请求重定向到/tea/的示例)。

/tea/  ->  /
/tea/abc  ->  /abc

下面是如何重写对coffee-svc的请求的URI(请注意,将/coffee请求重定向到/coffee/的示例)。

/coffee/  ->  /beans/
/coffee/abc  ->  /beans/abc