springboot https证书配置
如果公司有提供证书如:

拿到证书秘钥
可直接在springboot 的配置文件中配置:
server.ssl.key-store=classpath:cert.pfx
server.ssl.key-store-password=XXXXXXX
server.ssl.keyStoreType=PKCS12
server.ssl.key-password=XXXXXXXX
注意cert.pfx文件的位置

启动服务访问:这种只支持https
访问ok;
如果要同时支持http自动转换为https(springboot2.x)
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
/**
* Created by sWX605049 on 2019/7/31;
*/
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
} *//**
* http重定向到https
* 由于低层获取动态token的业务不支持springboot2.x
* @return
*//*
@Bean
public TomcatServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint constraint = new SecurityConstraint();
constraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("*/*");
constraint.addCollection(collection);
context.addConstraint(constraint);
}
};
tomcat.addAdditionalTomcatConnectors(httpConnector());
return tomcat;
} //注意:https默认端口443 ,然后会跳转到访问80端口
@Bean
public Connector httpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
//Connector监听的http的端口号
connector.setPort(8080);
connector.setSecure(false);
//监听到http的端口号后转向到的https的端口号
connector.setRedirectPort(8443);
return connector;
}
}
springboot 1.5.x
/**
* @return
*/
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {
@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(initiateHttpConnector());
return tomcat;
} /**
* @return Connector
*/
private Connector initiateHttpConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080); // http端口
connector.setSecure(false);
connector.setRedirectPort(8443); // application.properties中配置的https端口
return connector;
}
http://localhost:8080的时候系统会自动重定向到https://localhost:8443这个地址上
springboot https证书配置的更多相关文章
- HTTPS 证书配置
HTTPS 证书配置 现在阿里云和腾讯云都支持申请 HTTPS 证书,这里不再提,有需要的可自行google解决方案. 本文主要介绍的是通过 letsencrypt 申请免费的HTTPS证书,并将其配 ...
- nginx 反向代理及 https 证书配置
nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...
- Https证书配置
本文介绍配置免费证书的方法 具体步骤: 一.获取免费CA证书 步骤1到腾讯云找到: 二.申请完成 后域名验证指引 申请域名型证书,可以通过以下方式验证域名的所有权: 1. 手动 DNS 验证 通过解析 ...
- nginx 之 https 证书配置
HTTPS原理和作用 为什么需要HTTPS 原因:HTTP不安全 传输数据被中间人盗用.信息泄露 数据内容劫持.篡改 HTTPS协议的实现 对传输内容进行加密以及身份验证 对称加密:加密秘钥和解密秘钥 ...
- springboot下https证书配置
没有证书的小伙伴首先申请一个阿里云免费证书,按照我的步骤来操作 1.购买页面是这样的 按照顺序选择 神奇的一幕出现了 然后就去购买成功,我们会看到证书没有签发,我们需要去申请 填写需要绑定的域名 一般 ...
- apache2 以及https证书配置
环境Ubuntu12.04 server 配置 1,首先在进入找到/etc/apache2/apache2.conf的配置文件,里面有包含了较多配置文件的路径如:httpd.conf/ports.co ...
- nginx https证书配置
1. Nginx配置 server { listen 443; #指定ssl监听端口 server_name www.example.com; ssl on; #开启ssl支持 ssl_certifi ...
- Apache https 证书配置...
没啥好说的..赋值粘贴 !! Listen 443 SSLSessionCache "shmcb:/apache/logs/ssl_scache(512000)" SSLSessi ...
- apache2 aliyun https证书配置
SSLCertificateFile /etc/apache2/cert2019/2154762_www..com_public.crt SSLCertificateKeyFile /etc/apac ...
随机推荐
- MVC设计模式简介
刚刚学习了MVC相关知识,在这里进行一下总结MVC设计模式提高了Java开发中的代码可读性,提高了开发效率,实乃开发利器 1在MVC中由客户端发送一个带参数的请求,经过servlet处理后做出相应的处 ...
- GitHub 热点速览 Vol.12:不可思议的浏览器 browser-2020 周涨 star 超 3 千
作者:HelloGitHub-小鱼干 摘要:本周的 GitHub Trending 像极最近的天气,温暖如春突然来个急降温.新晋 GitHub 项目重启屈指可数的模式,好在老项目们表现甚好.比如一周就 ...
- LeetCode#232-Implement Queue using Stacks-用栈实现队列
一.题目 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部. pop() -- 从队列首部移除元素. peek() -- 返回队列首部的元素. empty() -- 返回队列 ...
- 面试刷题11:java系统中io的分类有哪些?
随着分布式技术的普及和海量数据的增长,io的能力越来越重要,java提供的io模块提供了足够的扩展性来适应. 我是李福春,我在准备面试,今天的问题是: java中的io有哪几种? java中的io分3 ...
- python爬虫常用库和安装 -- windows7环境
1:urllib python自带 2:re python自带 3:requests pip install requests 4:selenium 需要依赖chrome ...
- Mysql常用sql语句(一)- 操作数据库
21篇测试必备的Mysql常用sql语句,每天敲一篇,每次敲三遍,每月一循环,全都可记住!! https://www.cnblogs.com/poloyy/category/1683347.html ...
- 快速理解编码,unicode与utf-8
1.为什么编码,因为cpu只认识数字2.ASCII 一个字符共占7位,用一个字节表示,共128个字符3.那么ASCII浪费了最高位多可惜,出现了ISO-8859-1,一个字节,256个字符,很多协议的 ...
- Swagger2 初始用
1.结合Spring-Boot 引入 pom 依赖 <dependency> <groupId>io.springfox</groupId> <artifa ...
- ArrayList中的Iterator详解
每个实现Iterable接口的类必须提供一个iterator方法,返回一个Iterator对象,ArrayList也不例外 public Iterator<E> iterator() { ...
- 蓝桥杯 K好数(Java)
越来越觉得自己菜,一道简单的动态规划写不出来,题解也是看了很多份才看懂了,所以尽量以图表的方式写了题解,希望我的题解能帮到其他人吧.(;´Д`) 首先是题目: 输入描述: 输入包含两个正整数,K和L. ...