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` 系统属性来覆盖)。