SpringBoot 配置HTTPS
2018-02-23 10:01
801 查看
参考文章一:https://www.cnblogs.com/badboyf/p/6145642.html
参考文章二:http://blog.csdn.net/RO_wsy/article/details/51319963
- 通过keytool生成
生成证书参考文章:https://www.cnblogs.com/zhangzb/p/5200418.html
通过授权机构购买
在application.proereties中配置HTTPS
一般HTTPS需要将服务的启动端口设置为443才可以:
将HTTP请求重定向到HTTPS(可选)
参考文章二:http://blog.csdn.net/RO_wsy/article/details/51319963
添加SSL证书
两种方式:- 通过keytool生成
生成证书参考文章:https://www.cnblogs.com/zhangzb/p/5200418.html
通过授权机构购买
开启HTTPS
默认情况下Spring Boot内嵌的Tomcat服务器会在8080端口启动HTTP服务,Spring Boot允许在application.properties中配置HTTP或HTTPS,但是不可同时配置,如果两个都启动,至少有一个要以编程的方式配置,Spring Boot官方文档建议在application.properties中配置HTTPS,因为HTTPS比HTTP更复杂一些。在application.proereties中配置HTTPS
# set https server.ssl.key-store= classpath:cert/xxx.pfx server.ssl.key-store-password= xxx server.ssl.keyStoreType= PKCS12 # server.ssl.keyAlias: tomcat # HTTP重定向到HTTPS用到 hpsy.port= 8080
一般HTTPS需要将服务的启动端口设置为443才可以:
# application.properties server.port = 443
将HTTP请求重定向到HTTPS(可选)
package com.redsoft.epip.config; import org.apache.catalina.connector.Connector; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * * 配置HTTP访问重定向到HTTPS * * <pre> * 配置HTTP访问重定向到HTTPS * </pre> * * @author lixiaodong * @date 2017年12月21日 * @since 1.0 * */ @Configuration public class HttpsConfiguration { @Value("${hpsy.port}") private int port; @Bean public EmbeddedServletContainerFactory s b8b7 ervletContainer() { TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); tomcat.addAdditionalTomcatConnectors(createHttpConnector()); return tomcat; } private Connector createHttpConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(port); connector.setSecure(false); return connector; } }
相关文章推荐
- Spring Boot SSL [https]配置例子
- spring boot 配置https和SSL
- SpringBoot初始教程之Tomcat、Jetty优化以及Https配置(九)
- spring boot 配置 https|ssl
- 详解SpringBoot初始教程之Tomcat、Https配置以及Jetty优化
- SpringBoot初始教程之Tomcat、Jetty优化以及Https配置(九)
- Springboot配置使用ssl,使用https
- spring boot配置Https单向认证和双向认证
- spring boot 配置ssl证书实现https
- https spring boot (tomcat) 阿里云服务器配置
- 【spring boot】配置ssl证书实现https
- SpringMvc和SpringBoot配置Tomcat支持Https
- SpringBoot加https的配置
- spring boot https配置
- 在springboot中配置https安装证书 Unable to Start embedded TomCat
- Springboot项目使用Nginx 并配置 HTTPS
- 企业分布式微服务云SpringCloud SpringBoot mybatis (十九)Spring Boot 自定义配置文件
- Spring Boot 一些常用的pom配置
- spring-boot读取props和yml配置文件
- Spring Boot 坑区 之 配置文件