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