关于springcloud gateway配置

我的配置如下:

  routes:
    - id: provider-base
      uri: http://localhost:7001/
      predicates:
        - Path=/api/**

现在是想通过访问 网关host/api/test 来访问到 http://localhost:7001/test,现在的配置无法实现,无论怎么请求,都被转发到了http://localhost:7001/,请教各路大神应该如何配置。

阅读 3.4k
3 个回答

spring:
cloud:

gateway:
  discovery:
    locator:
      enabled: true
  routes:
    - id: provider-base
      uri: http://localhost:7001/
      filters:
        - StripPrefix=2 # Path有几级目录就写几
      predicates:
        - Path=/api/base/**

添加 RewritePath filter, 将 /api 重写为 /

  routes:
    - id: provider-base
      uri: http://localhost:7001/
      predicates:
        - Path=/api/**
      filters:
        - RewritePath=/api, /
新手上路,请多包涵

看您配置的这里累,建议你直接替换spring-cloud-gateway为fizz-gateway,都是基于webflux,性能还比spring-cloud-gateway要好,自带后台配置界面,热更新,无需重启。也不用编码了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进