Kubernetes Nginx Ingress删除部分URL [英] Kubernetes Nginx Ingress removing part of URL

查看:171
本文介绍了Kubernetes Nginx Ingress删除部分URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Kubernetes中(在AKS上)部署一个简单的应用程序,该应用程序位于使用Nginx的Ingress后面,并使用Nginx掌舵图进行了部署.我有一个问题,由于某种原因,Nginx似乎没有将完整的URL传递给后端服务.

I'm deploying a simple app in Kubernetes (on AKS) which is sat behind an Ingress using Nginx, deployed using the Nginx helm chart. I have a problem that for some reason Nginx doesn't seem to be passing on the full URL to the backend service.

例如,我的Ingress是使用 http://app.client.com 的URL设置的,并且/app1g转到 http://app.client.com/app1 的路径可以正常工作.但是,如果我尝试转到 http://app.client.com/app1/service1 我刚到 http://app.client.com/app1 ,它似乎正在剥离路径之后的一切.

For example, my Ingress is setup with the URL of http://app.client.com and a path of /app1g going http://app.client.com/app1 works fine. However if I try to go to http://app.client.com/app1/service1 I just end up at http://app.client.com/app1, it seems to be stripping everything after the path.

我的Ingress看起来像这样:

My Ingress looks like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  creationTimestamp: "2019-04-03T12:44:22Z"
  generation: 1
  labels:
    chart: app-1.1
    component: app
    hostName: app.client.com
    release: app
  name: app-ingress
  namespace: default
  resourceVersion: "1789269"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/app-ingress
  uid: 34bb1a1d-560e-11e9-bd46-9a03420914b9
spec:
  rules:
  - host: app.client.com
    http:
      paths:
      - backend:
          serviceName: app-service
          servicePort: 8080
        path: /app1
  tls:
  - hosts:
    - app.client.com
    secretName: app-prod
status:
  loadBalancer:
    ingress:
    - {}

如果我转而使用该服务并直接点击该服务,则它会起作用.

If I port forward to the service and hit that directly it works.

推荐答案

所以我找到了答案.从Nginx v0.22.0开始,您似乎需要使用捕获组来捕获请求URI中的所有子字符串.在0.22.0之前,仅使用 nginx.ingress.kubernetes.io/rewrite-target:/可用于任何子字符串.现在没有.我需要修改入口才能使用此功能:

So I found the answer to this. It seems that as of Nginx v0.22.0 you are required to use capture groups to capture any substrings in the request URI. Prior to 0.22.0 using just nginx.ingress.kubernetes.io/rewrite-target: / worked for any substring. Now it does not. I needed to ammend my ingress to use this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  creationTimestamp: "2019-04-03T12:44:22Z"
  generation: 1
  labels:
    chart: app-1.1
    component: app
    hostName: app.client.com
    release: app
  name: app-ingress
  namespace: default
  resourceVersion: "1789269"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/app-ingress
  uid: 34bb1a1d-560e-11e9-bd46-9a03420914b9
spec:
  rules:
  - host: app.client.com
    http:
      paths:
      - backend:
          serviceName: app-service
          servicePort: 8080
        path: /app1/?(.*)
  tls:
  - hosts:
    - app.client.com
    secretName: app-prod
status:
  loadBalancer:
    ingress:
    - {}

这篇关于Kubernetes Nginx Ingress删除部分URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆