2

我正在使用 Spring Boot + Cloud | Zuul 代理(org.springframework.cloud:spring-cloud-starter-zuul:1.0.0.RELEASE)。我有以下配置。


info:
  component: Zuul Server
endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false
zuul:
  ignoredServices: "*"
  proxy:
     mapping: /api/v1
     addProxyHeaders: true
  routes:
    service:
       path: /service/**
       serviceId: service
       stripPrefix: false
server:
  port: 8765
logging:
  level:
    ROOT: INFO
    org.springframework.web: INFO
eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/


我希望访问 URL 服务为http://localhost:8765/api/v1/service,如上述配置中所做的那样(参考:https ://github.com/joshlong/microservices-lab/blob/master/api-网关/网关/src/main/resources/application.yml)。

但这不起作用,URL http://localhost:8765/service有效。

有没有办法实现这一点,因为我不希望各个服务具有 /api/v1 上下文。

4

1 回答 1

4

不知道你从哪里得到的zuul.proxy.*选项。它们无效。zuul.addProxyHeaders已验证。

你想要的是zuul.prefix=/api/v1. 默认是在转发时去除该前缀。所以/api/v1/service转发到/service

于 2015-09-04T00:03:29.520 回答