gpt4 book ai didi

security - 为 Spring Boot 后端使用通配符 ssl 证书

转载 作者:太空宇宙 更新时间:2023-11-03 13:21:07 25 4
gpt4 key购买 nike

我已经从我的托管商 (Hoster X) 那里为我的域获取了通配符 SSL 证书,例如域名.com。

现在我有一个在服务器 A 上运行的 Spring Boot 后端(不托管在 Hoster X,IP:1.1.1.1,URL:api.domain.com)和我的前端在另一个服务器 B 上运行(托管在 Hoster X,IP :2.2.2.2, URL app.domain.com).

api.domain.com 到 IP 1.1.1.1 的重定向是通过 Hoster X 的 DNS 配置中的 A 资源记录设置的,因为 domain.com 已在此处注册。

enter image description here

在我的 Spring Boot 后端上安装证书的一般方法是什么,以便我的前端和后端之间的通信是安全的?我是否必须下载通配符证书才能将其安装到后端 keystore 中?据我所知,我只能在托管在 Hoster X 服务器上的域上的托管菜单中配置 SSL 证书。

最佳答案

在后端服务器上,使用openssl和以下命令将私钥文件、证书文件和CA文件合并到一个pkcs12 keystore中:

openssl pkcs12 -export -in <certfile> -inkey <keyfile> -out <keystorefile> -name tomcat -CAfile <cacertfile> -caname root

系统会提示您输入 keystore 密码。现在将生成的 keystore 文件(扩展名“p12”)复制到 Spring Boot 应用程序的资源目录。

现在在 application.yml 中设置 Spring Boot SSL 配置:

server:
port: 8443

# Spring SSL configuration
ssl:
enabled: true
key-store: classpath:keystore.p12
key-store-password: "<KeystorePassword>"
keyStoreType: PKCS12
keyAlias: tomcat

或者,将 keystore.p12 复制到后端服务器的某处,并指向具有绝对路径的位置:

server:
ssl:
key-store: /path/to/keystore.p12

在前端机器的 DNS 设置中创建一个 A 记录很重要,这样所有前端对后端的请求都会通过对域的调用而不是 IP,因为通配符证书仅对域有效。

关于security - 为 Spring Boot 后端使用通配符 ssl 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52421878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com