[英]Kubernetes NGINX Ingress changes HTTP request from a POST to a GET
I'm using Kubernetes that is bundled with Docker-for-Mac. 我正在使用与Docker-for-Mac捆绑在一起的Kubernetes。 I'm trying to configure an Ingress that routes http requests starting with /v1/ to my backend service and /ui/ requests to my Angular app. 我正在尝试配置一个Ingress,它将以/ v1 /开头的http请求路由到我的后端服务和/ ui /请求到我的Angular应用程序。
My issues seems to be that the HTTP method of the requests are changed by ingress (NGINX) from a POST to a GET. 我的问题似乎是请求的HTTP方法被入口(NGINX)从POST更改为GET。
I have tried various rewrite rules, but to no avail. 我尝试了各种重写规则,但无济于事。 I even switched from Docker-for-Mac to Minikube, but the result is the same. 我甚至从Docker-for-Mac切换到Minikube,但结果是一样的。
If I use a simple ingress with no paths (just the default backend) then the service is getting the correct HTTP method. 如果我使用没有路径的简单入口(只是默认后端),那么服务就是获得正确的HTTP方法。 The ingress below works: 下面的入口工作:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
spec:
backend:
serviceName: backend
servicePort: 8080
But this ingress does not: 但是这个入口没有:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /v1
backend:
serviceName: backend
servicePort: 8080
- path: /ui
backend:
serviceName: webui
servicePort: 80
When I debug the "backend" service I see that the HTTP Request is a GET instead of a POST. 当我调试“后端”服务时,我看到HTTP请求是GET而不是POST。
I read somewhere that NGINX rewrites issue a 308 (permanent) redirect and the HTTP method is changed from a GET to a POST, but if that is the case how can I configure my ingress to support different paths for different services that require POST calls? 我在某处读到NGINX重写了一个308(永久)重定向,并且HTTP方法从GET更改为POST,但如果是这样的话,我如何配置我的入口以支持需要POST调用的不同服务的不同路径?
I found the solution to my problem. 我找到了解决问题的方法。 When I add host:
to the configuration then the http method is not changed. 当我将host:
添加到配置时,http方法不会更改。 Here is my current ingress yaml (the rewrite and regex are used to omit sending the /v1 as part of the backend URL) 这是我当前的入口yaml(重写和正则表达式用于省略发送/ v1作为后端URL的一部分)
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- host: localhost
http:
paths:
- path: /v1(/|$)(.*)
backend:
serviceName: gateway
servicePort: 8080
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.