另一个Nginx Ingress重写目标问题 [英] Another nginx ingress rewrite-target problem
问题描述
我有一个服务和一个带有kubenetes nginx入口控制器的入口资源.我希望URL的/student
路径转到应用程序的根目录,并匹配student
之后的其他任何URL段.
I have one service and a single ingress resource with kubenetes nginx ingress controller. I want the /student
path of my url to go to the root of the application and match any other url segments which follow the student
.
例如: http://example.com/student/ver 应该与
For example: http://example.com/student/ver should match the /ver
route of my application.
但是,我的入口始终以/student
网址路径作为其他网址段的前缀来访问应用程序.如果我呼叫 http://example.com/student/ver ,我的应用程序将被相同的文件打网址(student/ver
).
However, my ingress always hit the application with the /student
url path prefixing the other url segments. If I call http://example.com/student/ver, my application is hit with the same url (student/ver
).
我的入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
name: ingress-resource
spec:
rules:
- host: example.com
http:
paths:
- backend:
serviceName: lesson-streaming
servicePort: 80
path: /student
我花了几天时间,一次都没有成功.
I spent days with this and was not successful once.
入口更改为以下内容-不是我的请求说http 404
The ingress is changed to the following - not my requests say http 404
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/rewrite-target: /$2
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
name: ingress-resource
namespace: default
spec:
rules:
- host: example.com
http:
paths:
- backend:
serviceName: lesson-streaming
servicePort: 80
path: /student(/|$)(.*)
推荐答案
您可以按照链接以正确使用rewrite-target
批注并保持右键nginx.ingress.kubernetes.io/rewrite-target
.
You can follow the link to use the rewrite-target
annotation correctly and keep the right key nginx.ingress.kubernetes.io/rewrite-target
.
apiVersion: networking.k8s.io/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(/|$)(.*)
这篇关于另一个Nginx Ingress重写目标问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!