我已经使用nginx-stable舵图安装了nginx并按如下所示配置了入口规则。虽然它仅适用于如下的根路径,
/user/login - working
/user/register - working
/foo/user/login - not working
/foo/user/register - not working
我已经按照文档ingress nginx rewrite中所述配置了重写目标,但是无法使其正常工作。不知道我在做什么错。
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路径和入口的调用返回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" "-"
答案 0 :(得分:4)
有two nginx ingress controllers个OSS和Plus。您已经安装了Plus,但由于在批注中使用了nginx.ingress.kubernetes.io
,因此需要安装一个here的OSS。
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install my-release ingress-nginx/ingress-nginx
编辑:
nginx.ingress.kubernetes.io/use-regex: true
应该删除,因为该路径中没有正则表达式,因此没有必要。