例如,我有一条规则(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变量或类似的东西? >
答案 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/(.*)