Spring Cloud Gateway 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

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

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

猜你喜欢

转载自blog.csdn.net/u013702678/article/details/88747719
今日推荐