Nginx入口控制器路径重写不起作用

I've installed nginx using nginx-stable helm chart and configured ingress rules as follows. Though it's working only for root path as follows,

/user/login - working
/user/register - working
/foo/user/login - not working
/foo/user/register - not working

I've configured rewrite target as mentioned in the document ingress nginx rewrite but couldn't make it to work. Not sure what I'm doing wrong.

 apiVersion: networking.k8s.io/v1beta1
 kind: Ingress
 metadata:
   name: foosrv-ingress
   annotations:
     kubernetes.io/ingress.class: nginx
     nginx.ingress.kubernetes.io/rewrite-target: /$2
     nginx.ingress.kubernetes.io/use-regex: true
     nginx.ingress.kubernetes.io/ssl-redirect: false
     nginx.ingress.kubernetes.io/enable-rewrite-log: true
 spec:
   rules:
   - http:
       paths:
       - path: /foo(/|$)(.*)
         backend:
           serviceName: foosrv-service
           servicePort: 5500
       - path: /
         backend:
           serviceName: foosrv-service
           servicePort: 5500

显然,它甚至无法识别/foo(/|$)(.*)路径规则。如下所示,在对foo path和ingress的调用返回404时,在pod中没有看到任何日志,

192.168.65.3 - - [23/May/2020:12:40:30 +0000] "GET /user/login HTTP/1.1" 200 1685 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" "-"
192.168.65.3 - - [23/May/2020:12:40:34 +0000] "GET /foo/user/login HTTP/1.1" 404 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" "-"
评论
babay
babay

There are two nginx ingress controllers OSS and Plus.You have installed the Plus but you need to install the OSS one here because you are using nginx.ingress.kubernetes.io in the annotations.

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install my-release ingress-nginx/ingress-nginx
点赞
评论