I'm trying to do the following uri manipulation in the Ingress-Nginx controller ( helm.sh/chart=ingress-nginx-4.2.0
)
If the URI is exactly /
, pass https://example.com/
-to-> https://backend_server/devportal/
But if the URI matches this pattern (/a|/b|/c)
, then just forward to https://backend_server/a|b|c
The seemingly simple requirement worked like this in an Nginx config:
server {
listen *:443 ssl; # Listen on port 443
location / {
proxy_pass https://backend_server/devportal/;
proxy_redirect https://backend_server/devportal/ /;
# proxy_cookie_path /devportal /;
}
location ~ (/a|/b|/c) {
proxy_pass https://backend_server;
proxy_redirect https://backend_server/devportal/ /;
}
}
Which I can't replicate on ingress-nginx
. I tried the following:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/backend-protocol: HTTPS
nginx.ingress.kubernetes.io/proxy-connect-timeout: 90s
nginx.ingress.kubernetes.io/proxy-read-timeout: 90s
nginx.ingress.kubernetes.io/proxy-redirect-from: /devportal/
nginx.ingress.kubernetes.io/proxy-redirect-to: /
nginx.ingress.kubernetes.io/proxy-send-timeout: 90s
nginx.ingress.kubernetes.io/rewrite-target: /devportal/$1
# nginx.ingress.kubernetes.io/app-root: /devportal
name: multitenancy-ingress
namespace: wso2
spec:
rules:
- host: example.com
http:
paths:
- backend:
service:
name: my-svc
port:
name: servlet-https
path: /(.*)
pathType: ImplementationSpecific
tls:
- hosts:
- example.com
secretName: my-tls
When going to https://example.com/
, the backend application receives a /
request ( GET / HTTP/1.1 302
)
Did you try to use nginx.ingress.kube.netes.io/stream-snippet annotation for ingress?
Can you try to use the working configuration by using this annotation like the in the docs: https://github.com/kube.netes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations.md#stream-snippet
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.