Kubernetes NGINX Ingress将HTTP请求从POST更改为GET [英] Kubernetes NGINX Ingress changes HTTP request from a POST to a GET
问题描述
我正在使用与Docker-for-Mac捆绑在一起的Kubernetes.我正在尝试配置一个Ingress,将以/v1/开头的http请求路由到我的后端服务,并将/ui/请求路由到我的Angular应用程序.
I'm using Kubernetes that is bundled with Docker-for-Mac. 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.
我的问题似乎是请求的HTTP方法是由Ingress(NGINX)从POST更改为GET.
My issues seems to be that the HTTP method of the requests are changed by ingress (NGINX) from a POST to a GET.
我尝试了各种重写规则,但无济于事.我什至从Mac的Docker切换到Minikube,但是结果是一样的.
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.
如果我使用一个没有路径的简单入口(只是默认的后端),则该服务将获取正确的HTTP方法. 下面的入口有效:
If I use a simple ingress with no paths (just the default backend) then the service is getting the correct HTTP method. The ingress below works:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress
spec:
backend:
serviceName: backend
servicePort: 8080
但是此入口不会:</p>
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
当我调试后端"服务时,我看到HTTP请求是GET而不是POST.
When I debug the "backend" service I see that the HTTP Request is a GET instead of a POST.
我读到某个地方,NGINX进行了重写,发出了308(永久)重定向,并且HTTP方法从GET更改为POST,但是如果是这种情况,我该如何配置我的入口以支持需要的不同服务的不同路径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?
推荐答案
我找到了解决问题的方法.当我在配置中添加host:
时,http方法不会更改.这是我当前的入口Yaml(重写和正则表达式用于省略发送/v1作为后端URL的一部分)
I found the solution to my problem. When I add host:
to the configuration then the http method is not changed. Here is my current ingress yaml (the rewrite and regex are used to omit sending the /v1 as part of the backend 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
这篇关于Kubernetes NGINX Ingress将HTTP请求从POST更改为GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!