Kong路由和上游服务器路径

问题描述 投票:0回答:1

我在 Kong 有以下路由服务配置:

- name: test
  host: test-service
  port: 80
  protocol: http
  path: /endpoint/
  routes:
    - name: test_route
      strip_path: true
      preserve_host: true
      paths:
        - /login

我试图理解以下行为:

  • 当我访问
    http://localhost/login
    时,我最终会在浏览器中看到
    http://localhost/endpoint
  • 但是,当我尝试访问
    http://localhost/login/test/page
    时,什么都不会改变,我仍然在
    http://localhost/login/test/page
    上的浏览器中,并且上游服务器正确地处理了我的请求

我的期望是使用

http://localhost/login/test/page
,我的浏览器最终将拥有
http://localhost/endpoint/test/page
。看来我理解错了。

我明白,在这种情况下,Kong 将使用上游路径作为

/endpoint/test/page
,因为我有
strip_path: true

但是,如果我想以

http://localhost/endpoint/test/page
结束,以防我在浏览器中访问
http://localhost/login/test/page
,如何更改它?

uri kong kong-plugin
1个回答
0
投票

我在我的实验室测试了你的案例。它正在发挥作用。

[07/Aug/2023:06:43:22 +0000]“GET /endpoint/123 HTTP/1.1”200 5“-”“Mozilla/5.0(Windows NT 10.0;Win64;x64)

当我卷曲 /login/123 时

© www.soinside.com 2019 - 2024. All rights reserved.