是否有最佳实践来实现将规则重写为root的进入规则

时间:2019-10-25 14:26:29

标签: kubernetes nginx-ingress

例如,我有一条规则(https://kubernetes.github.io/ingress-nginx/examples/rewrite/):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something(/|$)(.*)

因此,转到rewrite.bar.com/something的所有内容都将转到http-svc/。如果http-svc将回答另一个位置,例如/static将被重定向到rewrite.bar.com/static,然后我们开始-404。我想知道是否有任何简单明了的解决方案来解决这种情况,而无需开发人员实现proxy_path变量或类似的东西? >

尝试过Make links in response relative to new path

1 个答案:

答案 0 :(得分:1)

将重写注释更改为$ 1。注意我也更改了路径正则表达式。那应该做。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something/(.*)