TLS and 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 Handshake

网关会维护一个供它用于路由到后端的客户端池。通过 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