11.06 SpringBoot中教你手把手配置 https

升級 https 記錄

1、去阿里雲購買證書(免費版),並提交審核資料

SpringBoot中教你手把手配置 https

購買的證書

2、下載證書

SpringBoot中教你手把手配置 https

下載證書

3、查看上圖頁面的第三步

SpringBoot中教你手把手配置 https

JKS證書安裝

4、在證書目錄下執行阿里雲提供的命令,密碼都填 pfx-password.txt 中的內容(三次),會生成 your-name.jks 文件。

SpringBoot中教你手把手配置 https

生成 jks 證書

此處我已改名為 any.jks

5、將 any.jks 複製到 spring boot 應用的 resources 目錄下

SpringBoot中教你手把手配置 https

移動證書

6、在 application.yml 中配置證書及端口,密碼填寫第四步中的密碼

SpringBoot中教你手把手配置 https

image.png

此配置會使 Undertow 容器監聽 443 端口,那麼只有在域名前添加 https:// 才能訪問網站內容,添加 http:// 則不行,所以需要讓 Undertow 容器監聽 80 端口,並將 80 端口的所有請求重定向到 443 端口,即完成 http 到 https 的跳轉。

7、添加 SslConfig.java ,配置 Undertow 監聽 80 端口。

8、在 Spring Security 中配置 80 端口到 443 端口的映射 【待完善】

至此,重新打包應用,重新發布應用,即完成了 http 到 https 的升級, https 能讓網站更安全,有興趣的試試吧。


分享到:


相關文章: