简体   繁体   English

Kubernetes NGINX Ingress将HTTP请求从POST更改为GET

[英]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.

相关问题 如何调试 Kubernetes nginx 从 HTTP 到 Z0E8433F9A404F1F3DBA1ZC26 的入口重定向 - How to debug Kubernetes nginx Ingress redirection from HTTP to HTTPS nginx 入口拒绝 HTTP POST 请求,状态码为 400 - nginx ingress rejects HTTP POST request with a 400 code status code How to setup nginx ingress controller, such that the kubernetes pod remains http but the nginx serves request on https - How to setup nginx ingress controller , such that the kubernetes pod remains http but the nginx serves request on https kubernetes nginx ingress无法将HTTP重定向到HTTPS - kubernetes nginx ingress fails to redirect HTTP to HTTPS 无法使用 Google Kubernetes Engien Nginx 入口控制器获得 HTTP 基本身份验证 - Can't get HTTP basic auth with Google Kubernetes Engien Nginx ingress controller Nginx将POST请求从https重定向到http - Nginx redirect the POST request from https to http 通过请求 header 和请求正文在 kubernetes nginx 入口 Z594C103F2C6E14C01AZ8AB059F03 - Pass request header and request body in kubernetes nginx ingress controller Kubernetes - Ingress - Nginx:将查询参数从原始请求转发到 auth-url - Kubernetes - Ingress - Nginx : Forward query parameters from original request to auth-url Kubernetes nginx 入口 ssl - Kubernetes nginx ingress ssl Kubernetes:使用 NGINX 入口简单扇出保留 HTTP 方法 - Kubernetes: Preserving HTTP method with NGINX Ingress simple fanout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM