【问题标题】:How to disable Zuul modifying request URL when forwarding to a service?转发到服务时如何禁用 Zuul 修改请求 URL?
【发布时间】:2019-11-07 11:12:08
【问题描述】:

这是我的 Zuul 配置(.yml 文件)

server:
  port: 8080
zuul:
  sensitiveHeaders:
  ignored-services: "*"
  routes:
    ui-service:
      path: /online-book-store/**
      serviceId: ui-service-v1
      stripPrefix: true
    auth-service:
      path: /auth/**
      serviceId: auth-service
    book-service:
      path: /book-service/**
      serviceId: book-service
    book-service-genres:
      path: /api/genres/**
      serviceId: book-service
  host:
    socket-timeout-millis: 10000
    connect-timeout-millis: 10000


eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:2580/eureka/

我面临的问题是,当我发送请求时:

<zuul_gateway>/api/genres/listAll 

该请求被转发到 &lt;book-service&gt;/listall,我希望它是&lt;book-service&gt;/api/genres/listAll

所以所有“匹配”的路径都被删除了。如何禁用此“功能” .

【问题讨论】:

    标签: spring routing netflix-zuul


    【解决方案1】:

    stripPrefix: false 设置为 book-service-genres。默认情况下,匹配的前缀被删除。

    【讨论】:

    • 我认为这在这种情况下不起作用,因为我实际上没有定义任何前缀,只有服务路径。正如文档所说:zuul.stripPrefix 仅适用于 zuul.prefix 中设置的前缀。它对给定路由路径中定义的前缀没有任何影响。
    猜你喜欢
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 2018-07-12
    • 2018-12-08
    • 2018-11-03
    • 1970-01-01
    • 2018-12-28
    • 2020-03-29
    相关资源
    最近更新 更多