赞
踩
1.首先去腾讯云或者阿里云申请免费ssl证书 不要自己生产 ,不然无法在服务器上使用
2. 获取证书之后 会生成一个 压缩包 打开 tomcat 的 文件 会有一个 text 文件 和 jks 文件
3.因为springboot使用的是内置tomcat,所以我这边选择tomcat文件,在resources目录下导入xxx.jks
密码在同文件夹的keystorePass.txt中
server:
port: 10001
ssl:
key-store: classpath:xxxxx.com.jks
key-password: u1u7497mw9835c
key-store-type: JKS
4.编写配置类
@Configuration public class TomcatConfig { @Bean TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() { TomcatServletWebServerFactory factory = 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); } }; factory.addAdditionalTomcatConnectors(createTomcatConnector()); return factory; } private Connector createTomcatConnector() { Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); connector.setScheme("http"); connector.setPort(8080); connector.setSecure(false); connector.setRedirectPort(443); return connector; } } nginx 代理转发 location /api/ { proxy_pass https://192.168.1.1:8088/deom/; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。