【问题标题】:How to redirect to https with Spring cloud gateway & ribbon如何使用 Spring Cloud Gateway 和 Ribbon 重定向到 https
【发布时间】:2022-10-19 15:04:05
【问题描述】:

我有 2 个使用 https 的微服务,我添加了 spring cloud gateway api 来集中路由,但我遇到了一个问题,它说:This combination of host and port requires TLS 我很确定这是因为我的网关上的路由配置,我没有太多经验在这一边,但如果有人可以帮助我。

这是我的春季网关路由配置:

  @Bean
  public RouteLocator gatewayRouter(RouteLocatorBuilder builder){
    return builder.routes()
        .route(p -> p.path("/api/v1/**")
            .uri("lb://statement"))
        .route( p -> p.path("/api/v3/**")
            .uri("lb://activiti-workflow"))
        .build();
  }

请我只想知道此配置是否会重定向到 https,因为在将 http 请求直接发送到微服务时它可以工作,但网关却不能。

【问题讨论】:

  • 如果您使用的是 eureka,则可以设置安全端口。否则你可以使用lbs://
  • 我在每个uri上使用了lbs://,错误消失了,返回200,但没有数据只是空白。保护我不太了解的端口,您可以参考一下吗?在此先感谢
  • 没有更多信息,我无能为力
  • 另外,请注意 Spring Cloud Netflix Ribbon 不再维护,其依赖项也没有升级。我们强烈建议改用 Spring Cloud LoadBalancer。

标签: spring ssl spring-cloud ribbon


【解决方案1】:

如果你在 eureka 中的后端服务提供 https,你可以像这样设置路由 uri:

uri: lb:https://your-service-name

或者

.uri("lb:https://your-service-name")

它就像 websocket 配置一样。关键类是org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter

更多信息见:https://cloud.spring.io/spring-cloud-gateway/reference/html/#the-routetorequesturl-filter

如果您的后端服务使用不安全的 HTTPS 证书,您可能需要这样配置:

spring:
  cloud:
    gateway:
      httpclient:
        ssl:
          useInsecureTrustManager: true

请参阅:https://cloud.spring.io/spring-cloud-gateway/reference/html/#tls-and-ssl

【讨论】:

    猜你喜欢
    • 2018-12-11
    • 2020-10-19
    • 2015-12-12
    • 2018-10-10
    • 2021-01-23
    • 2019-08-03
    • 2021-11-29
    • 2021-05-19
    • 1970-01-01
    相关资源
    最近更新 更多