117. 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

使用不安全的信任 Management 器不适合生产。对于生产部署,可以为网关配置一组可以通过以下配置信任的已知证书:

application.yml.

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

如果未为 Spring Cloud Gateway 提供受信任的证书,则使用默认的信任存储(可以使用系统属性 javax.net.ssl.trustStore 覆盖)。

117.1 TLS 握手

网关维护一个 Client 端池,该 Client 端池用于路由到后端。通过 https 进行通信时,Client 端会启动 TLS 握手。许多超时与此握手相关联。可以配置以下超时(显示默认值):

application.yml.

spring:
  cloud:
    gateway:
      httpclient:
        ssl:
          handshake-timeout-millis: 10000
          close-notify-flush-timeout-millis: 3000
          close-notify-read-timeout-millis: 0