首页 文章

Spring Boot Cloud | Zuul代理|附加URL /重写

提问于
浏览
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,如上面的配置(ref:https://github.com/joshlong/microservices-lab/blob/master/api-gateway/gateway/src/main/resources/application.yml)所示 .

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

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

1 回答

  • 2

    不知道你在哪里获得 zuul.proxy.* 选项 . 它们无效 . zuul.addProxyHeaders 有效 .

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

相关问题