【问题标题】:Spring Cloud Gateway in CloudFoundryCloudFoundry 中的 Spring Cloud Gateway
【发布时间】:2018-08-18 22:50:35
【问题描述】:

我一直在尝试让我的应用程序在将它们部署到 CloudFoundry 实例后运行。我使用的实例不允许使用 http 执行请求(它们只会超时),所以我必须将所有请求路由到 https。

我使用的组件/版本是:

  • Java 10
  • Spring Boot 2.0.4.RELEASE/Spring Cloud Finchley.SR1
  • spring-cloud-gateway
  • spring-cloud-config-server
  • spring-cloud-starter-netflix-eureka

失败的配置

EurekaClient 配置(在网关和 gw 应该路由到的后端)

eureka:
  client:
    serviceUrl:
      defaultZone: ${DISCOVERY_SERVICE_URL:http://localhost:8061}/eureka/
  instance:
    hostname: ${vcap.application.uris[0]:localhost}
    nonSecurePortEnabled: false
    securePortEnabled: true
    securePort: ${server.port}
    statusPageUrl: https://${eureka.instance.hostname}/actuator/info
    healthCheckUrl: https://${eureka.instance.hostname}/actuator/health
    homePageUrl: https://${eureka.instance.hostname}/
    secure-virtual-host-name: https://${vcap.application.application_uris[0]}

网关配置

spring:
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true
      routes:
      - id: user-service
        uri: lb://user-service
        predicates:
        - Path=/user/**
        filters:
        - RewritePath=/user/(?<segment>.*), /$\{segment}

我已经尝试过的事情:

  • docs 中描述的那样使用lb:https://user-service -> 据我所知,不会有任何效果
  • 使用应用的真实网址 (uri: https://user-service.cf-instance.io) -> 路由按预期工作。

但我不想在我的配置中定义 url,它们应该由 eureka 返回并由网关正确构建。

提前致谢

编辑:

这是/eureka/apps的输出 https://pastebin.com/WP3b6PQG

我目前正在努力将当前代码导入 GitHub,当我有时间了解清楚状态时,我将编辑这篇文章。

编辑 2:

您可以在my GitHub 找到完整示例(使用 SpringCloudGateway、Eureka...) 这是一个运行示例,应用的配置不会使用 Eureka。要使用 Eureka,必须在配置服务中采用 gateway-service-cloud.yml

- id: user-service uri: lb://user-service

请忽略文档服务,这还不行,我首先需要重写路径。

【问题讨论】:

  • 在 eureka 中是否有注册到安全端口的服务?
  • 是的,服务已在 eureka 仪表板中正确注册。当我单击仪表板中的 ID 时,我被重定向到服务的健康端点。对网关的响应也包含正确的 uri,但没有模式本身。所以我认为网关配置中缺少一些架构可以/将设置为 https。
  • 你能显示&lt;eurekaserver&gt;/eureka/apps的输出吗?
  • 我已编辑帖子以添加您要求的信息。今天我又做了一个测试。我部署了具有 2 种不同配置的应用程序。第一个是修复 https url,另一个是 lb 配置。 /eureka/apps 生成的 xml 完全相同(除了 ip、timestamps 和 id)。

标签: spring-boot spring-cloud netflix-eureka spring-cloud-gateway


【解决方案1】:

好的,我在用documentation-service 修复“路由”问题时找到了解决方案。

我的问题是将属性eureka.instance.securePort 设置为${server.port}。此属性必须设置为443(未设置时不应用默认的 443)。将其添加到我的配置中时,在推送我的应用程序后一切都按预期工作。

【讨论】:

  • 嗨@Konrad,我面临同样的问题。你能告诉我你在哪个服务中设置了 eureka.instance.securePort443 ?网关服务还是其他微服务?
  • 嘿@jackfr0st。看看我的提交历史。我已将所有 securePorts 设置为 443。github.com/konraifen88-home/home-monitor-aio/commit/…
猜你喜欢
  • 2021-07-23
  • 2017-12-10
  • 1970-01-01
  • 2021-10-20
  • 2016-06-17
  • 2019-01-21
  • 2018-11-15
  • 2019-09-16
  • 2020-07-31
相关资源
最近更新 更多