Springboot配置ssl证书踩坑记
1、准备材料
此为团队成员从let’s encrypt获取的免费ssl证书。分别有ca_bundle.crt,certificate.crt,private.key三个文件。
2、转换成.pfx格式证书
首先将ca_bundle.crt用文本软件打开,复制内容到certificate.crt文件中,格式如下:
-----BEGIN CERTIFICATE-----
…
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
…
-----END CERTIFICATE-----
随后打开https://www.chinassl.net/ssltools/convert-ssl.html进行在线证书格式转换。
3、Springboot配置
将生成好的.pfx复制到springboot中的resources文件目录下,并配置.yml/.properties:
server:
port: 443
ssl:
key-store: classpath:xxx.pfx
key-store-password: xxxx
key-store-type: PKCS12
enabled: true
如图为yml配置。在TzbApiApplication中配置:
/**
* http重定向到https
* @return
*/
@Bean
public ServletWebServerFactory servletContainer