如何修改 Kubernetes NGINX Ingress 中的代理路径
How can I modify the proxied path in a Kubernetes NGINX Ingress
基本上,我正在尝试这样做:
location / {
proxy_pass https://externaldomain.com/api/;
}
不向 nginx 传递服务器代码段,而是通过规范。
因此,如果请求命中 https://myingress.com/endpoint
,我的集群会为他们提供来自 https://externaldomain.com/api/endpoint
的内容
我设置了 ExternalName
服务:
apiVersion: v1
kind: Service
metadata:
name: api-proxy
spec:
type: ExternalName
externalName: externaldomain.com
以及到达它的 Ingress 路径,但没有更改路径:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/upstream-vhost: "externaldomain.com"
nginx.ingress.kubernetes.io/server-snippet: |
proxy_ssl_name externaldomain.com;
proxy_ssl_server_name on;
spec:
ingressClassName: nginx
rules:
- host: myingress.com
http:
paths:
- pathType: Prefix
backend:
service:
name: api-proxy
port:
number: 80
path: /
根据文档设置 proxy_redirect
注释应该可以解决问题:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#proxy-redirect
基本上,我正在尝试这样做:
location / {
proxy_pass https://externaldomain.com/api/;
}
不向 nginx 传递服务器代码段,而是通过规范。
因此,如果请求命中 https://myingress.com/endpoint
,我的集群会为他们提供来自 https://externaldomain.com/api/endpoint
我设置了 ExternalName
服务:
apiVersion: v1
kind: Service
metadata:
name: api-proxy
spec:
type: ExternalName
externalName: externaldomain.com
以及到达它的 Ingress 路径,但没有更改路径:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-ingress
annotations:
nginx.ingress.kubernetes.io/upstream-vhost: "externaldomain.com"
nginx.ingress.kubernetes.io/server-snippet: |
proxy_ssl_name externaldomain.com;
proxy_ssl_server_name on;
spec:
ingressClassName: nginx
rules:
- host: myingress.com
http:
paths:
- pathType: Prefix
backend:
service:
name: api-proxy
port:
number: 80
path: /
根据文档设置 proxy_redirect
注释应该可以解决问题:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#proxy-redirect