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.