700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 【SSL】【SpringBoot】【阿里云】【https】SpringBoot配置的阿里云ssl(完整版)

【SSL】【SpringBoot】【阿里云】【https】SpringBoot配置的阿里云ssl(完整版)

时间:2023-03-15 23:33:44

相关推荐

【SSL】【SpringBoot】【阿里云】【https】SpringBoot配置的阿里云ssl(完整版)

文章目录

一、获取阿里云免费一年SSL验证二、下载SSL证书,并整合到SpringBoot项目。

一、获取阿里云免费一年SSL验证

进入阿里云服务器,搜索SSL,选择SSL证书。

选择免费版SSL证书,并购买

输入SSL服务的域名和个人信息

这里的信息是需要你填到你所购买域名的地方,在哪购买的,就填到哪。(笔者这里是在腾讯云上购买的,所以下面的内容会填到腾讯云上。)

把刚刚知道的信息,复制粘贴填到对应的域名购买地方那。

点击验证,验证成功,提交审核,等待通知。(如果刚刚在域名DNS解析那填错了,点击验证是显示出错的。)

二、下载SSL证书,并整合到SpringBoot项目。

已部署那显示负载均衡了,代表你的SSL证书能是合法的了。点击下载

由于SpringBoot是内嵌tomcat的,因此,我们是要选择下载的服务器类型是Tomcat的。

下载的是一个压缩包,解压

① .pfx 文件是要放到SpringBoot项目里的resources目录下,即和application.properties同级目录下。

② pfx-password.txt文件里的内容是属于密码,需要写到application.properties里面去,还需要添加加载.pfx文件。

即需要在application.properties文件里添加下面两句。

server.ssl.key-store=classpath:.pfx

server.ssl.key-store-password=qpwHeBvg

SpringBoot项目配置https成功

但是,这有个问题,输入http访问的时候,并没有跳转到https,这是需要处理的。 所以,需要在启动类里添加处理,并且设置application.properties的端口为443。

@Bean

public Connector connector(){

Connector connector=new Connector(“org.apache.coyote.http11.Http11NioProtocol”);

connector.setScheme(“http”);

connector.setPort(602);

connector.setSecure(false);

connector.setRedirectPort(443);

return connector;

}

@Bean

public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector){

TomcatServletWebServerFactory tomcat=new TomcatServletWebServerFactory(){

@Override

protected void postProcessContext(Context context) {

SecurityConstraint securityConstraint=new SecurityConstraint();

securityConstraint.setUserConstraint(“CONFIDENTIAL”);

SecurityCollection collection=new SecurityCollection();

collection.addPattern(“/*”);

securityConstraint.addCollection(collection);

context.addConstraint(securityConstraint);

}

};

tomcat.addAdditionalTomcatConnectors(connector);

return tomcat;

}

输入localhost:602会自动转到https://localhost(完美结束)

【SSL】【SpringBoot】【阿里云】【https】SpringBoot配置免费的阿里云ssl(完整版) SpringBoot配置https(手把手教)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。