[英]Ingress Nginx inject subpath to root URI
I'm trying to do the following uri manipulation in the Ingress-Nginx controller ( helm.sh/chart=ingress-nginx-4.2.0
)我正在尝试在 Ingress-Nginx controller ( helm.sh/chart=ingress-nginx-4.2.0
) 中执行以下 uri 操作
If the URI is exactly /
, pass https://example.com/
-to-> https://backend_server/devportal/
如果 URI 恰好是/
,则传递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
但是如果 URI 匹配这个模式(/a|/b|/c)
,那么就转发到https://backend_server/a|b|c
The seemingly simple requirement worked like this in an Nginx config:看似简单的要求在 Nginx 配置中是这样工作的:
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
.我无法在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
)当转到https://example.com/
时,后端应用程序收到一个/
请求 ( GET / HTTP/1.1 302
)
Did you try to use nginx.ingress.kube.netes.io/stream-snippet annotation for ingress?您是否尝试使用 nginx.ingress.kube.netes.io/stream-snippet 注释进行入口?
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您能否尝试使用文档中的注释来使用工作配置: https://github.com/kube.netes/ingress-nginx/blob/main/docs/user-guide/nginx-configuration/annotations。 md#流片段
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.