1

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

我正在使用的组件/版本是:

  • 爪哇 10
  • Spring Boot 2.0.4.RELEASE/Spring Cloud Finchley.SR1
  • 春天云网关
  • 弹簧云配置服务器
  • 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}

我已经尝试过的事情:

  • 使用文档lb:https://user-service中描述的方式->据我所见将没有效果
  • 使用应用程序的真实网址 ( uri: https://user-service.cf-instance.io) -> 路由按预期工作。

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

提前致谢

编辑:

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

我目前正在努力将当前代码导入 GitHub,当我找到时间获得清晰的状态时,我将编辑这篇文章。

编辑2:

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

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

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

4

1 回答 1

2

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

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

于 2018-08-26T09:08:57.027 回答