如何使用Spring Cloud Gateway&丝带

发布于 2025-02-03 17:51:35 字数 561 浏览 4 评论 0原文

我有2个与HTTP一起使用的微服务,我添加了Spring Cloud Gateway API以集中路线,但我遇到了一个问题:主机和端口的组合需要TLS我很确定这是因为这是因为我网关上的路线配置,我在这方面没有太多经验,但是如果有人可以帮助我。

这是我的Spring Gateway路线配置:

  @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请求直接发送到其有效的微服务时,但与Gateway并非如此。

I have 2 microservices working with https, I added spring cloud gateway api to centralize the routes but I faced a problem where it says: This combination of host and port requires TLS I'm pretty sure that's because of the routes configuration on my gateway, I dont have much experience on this side but if someone could help me.

this is my spring gateway routes configuration :

  @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();
  }

Please I just want to know if this configuration will redirects to https or not, because while sending http requests directly to the microservices it works but with gateway is doesn't.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

洛阳烟雨空心柳 2025-02-10 17:51:35

如果您在尤里卡(Eureka)的后端服务提供HTTPS,则可以像这样设置路由URI:

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

或者

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

像WebSocket配置一样。密钥类是org.springframework.cloud.gateway.filter.routetetorequesturlfilter

更多信息,请参见: https://cloud.spring.io/spring-cloud-cloud-gateway/reference/reference/html/#the-routetetorequesturl-filter

使用不安全的https cert,您可能需要的配置以下内容:

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

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

If your backend services in eureka provide https, your can set route uri like this:

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

Or

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

It just like websocket configuration. The key class is org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter

More info see at: https://cloud.spring.io/spring-cloud-gateway/reference/html/#the-routetorequesturl-filter

If your backend services use insecure HTTPS cert, your may need config this:

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

See at: https://cloud.spring.io/spring-cloud-gateway/reference/html/#tls-and-ssl

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文