I am trying to add path based ingress rules for react web application. If I go to example.com/abc to abc application and example.com/xyz to Xyz application
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /abc(/|$)(.*)
backend:
serviceName: abc-service
servicePort: 80
- path: /xyz(/|$)(.*)
backend:
serviceName: xyz-service
servicePort: 80
But if I tried path / instead of /abc it works. Not for xyz
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /(.*)
backend:
serviceName: abc-service
servicePort: 80
- path: /xyz(/|$)(.*)
backend:
serviceName: xyz-service
servicePort: 80
Try this:
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- http:
paths:
- path: /abc/?(.*)
backend:
serviceName: abc-service
servicePort: 80
- path: /xyz/?(.*)
backend:
serviceName: xyz-service
servicePort: 80