现在的位置: 首页 > 编程语言 > 正文

SpringBoot配置https实操方法

2020年02月13日 编程语言 ⁄ 共 963字 ⁄ 字号 评论关闭

升级 https 记录

1、去阿里云购买证书(免费版),并提交审核资料

购买的证书

2、下载证书

下载证书

3、查看上图页面的第三步

JKS证书安装

4、在证书目录下执行阿里云提供的命令,密码都填 pfx-password.txt 中的内容(三次),会生成 your-name.jks 文件。

生成 jks 证书

此处我已改名为 any.jks

5、将 any.jks 复制到 spring boot 应用的 resources 目录下

移动证书

6、在 application.yml 中配置证书及端口,密码填写第四步中的密码

此配置会使 Undertow 容器监听 443 端口,那么只有在域名前添加 https:// 才能访问网站内容,添加 http:// 则不行,所以需要让 Undertow 容器监听 80 端口,并将 80 端口的所有请求重定向到 443 端口,即完成 http 到 https 的跳转。

7、添加 SslConfig.java ,配置 Undertow 监听 80 端口。

@Configurationpublic class SslConfig { @Bean public EmbeddedServletContainerFactory servletContainer() { UndertowEmbeddedServletContainerFactory undertowFactory = new UndertowEmbeddedServletContainerFactory(); undertowFactory.addBuilderCustomizers(new UndertowBuilderCustomizer() { @Override public void customize(Undertow.Builder builder) { builder.addHttpListener(80, "0.0.0.0"); } }); return undertowFactory; }}

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

至此,重新打包应用,重新发布应用,即完成了 http 到 https 的升级, https 能让网站更安全,有兴趣的试试吧。

本文标题: SpringBoot配置https实操方法

以上就上有关SpringBoot配置https实操方法的全部内容,学步园全面介绍编程技术、操作系统、数据库、web前端技术等内容。

抱歉!评论已关闭.