TLS 和 SSL

网关可以通过遵循常规的 Spring 服务器配置来监听 HTTPS 请求。以下示例展示了如何实现

application.yml
server:
  ssl:
    enabled: true
    key-alias: scg
    key-store-password: scg1234
    key-store: classpath:scg-keystore.p12
    key-store-type: PKCS12

您可以将网关路由到 HTTP 和 HTTPS 后端。如果要路由到 HTTPS 后端,您可以使用以下配置将网关配置为信任所有下游证书

application.yml
spring:
  cloud:
    gateway:
      httpclient:
        ssl:
          useInsecureTrustManager: true

使用不安全的信任管理器不适用于生产环境。对于生产部署,您可以使用以下配置为网关配置一组它可信任的已知证书

application.yml
spring:
  cloud:
    gateway:
      httpclient:
        ssl:
          trustedX509Certificates:
          - cert1.pem
          - cert2.pem

如果 Spring Cloud Gateway 没有配置受信任的证书,则会使用默认的信任库(您可以通过设置 `javax.net.ssl.trustStore` 系统属性来覆盖)。

TLS 握手

网关维护一个客户端池,用于路由到后端。当通过 HTTPS 通信时,客户端会发起 TLS 握手。与此握手相关联的超时时间可以通过以下方式进行配置(显示为默认值)

application.yml
spring:
  cloud:
    gateway:
      httpclient:
        ssl:
          handshake-timeout-millis: 10000
          close-notify-flush-timeout-millis: 3000
          close-notify-read-timeout-millis: 0
© . This site is unofficial and not affiliated with VMware.