我为user-service重写了以下配置,它应该删除'sso'或'user',并使用路径的其余部分重定向到user-service
nginx-ingress-controller: 0.32.0
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: user-service
namespace: pre-prod
annotations:
cert-manager.io/cluster-issuer: clusterissuer-selfsigned-default
ingress.kubernetes.io/rewrite-target: /$2/$4
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://example.com"
labels:
app: pre-prod
component: user-service
spec:
rules:
- host: example.com
http:
paths:
- path: /(user|sso)/(api|saml)(/|$)(.*)
backend:
serviceName: user-service
servicePort: 80
路径/sso/api/auth/sso/signin应该被转换为/api/auth/sso/signin,但是后端发送的响应是
error: "Not Found"
message: "No message available"
path: "/sso/api/auth/sso/signin"
status: 404
timestamp: "2021-01-20T09:47:04.544+0000"
172.18.240.0 - - [20/Jan/2021:09:47:04 +0000] "GET /sso/api/auth/sso/signin HTTP/1.1" 404 161 "https://example.com/login" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" 693 0.023 [pre-prod-user-service-80] [] 172.18.64.24:9090 166 0.022 404 a5844078b332b882056516aa50b0eb2b
有什么问题吗?
感谢注释有一个错别字,在nginx.ingress.kubernetes.io/rewrite-target:
nginx.