zoukankan      html  css  js  c++  java
  • springboot2 配置 https

    package cn.xiaojf.aibus.configure;
    
    import org.apache.catalina.Context;
    import org.apache.catalina.connector.Connector;
    import org.apache.coyote.http11.Http11NioProtocol;
    import org.apache.tomcat.util.descriptor.web.SecurityCollection;
    import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
    import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
    import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Profile;
    
    /**
     * http ssl 配置
     * @author xiaojf 2019/9/21 20:07
     */
    @Configuration
    @Profile("prod")
    public class HttpsConfigure {
    
        @Bean
        public ServletWebServerFactory servletWebServerFactory() {
            TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
                @Override
                protected void postProcessContext(Context context) {
                    SecurityConstraint securityConstraint = new SecurityConstraint();
                    securityConstraint.setUserConstraint("CONFIDENTIAL");
                    SecurityCollection securityCollection = new SecurityCollection();
                    securityCollection.addPattern("/*");
                    securityConstraint.addCollection(securityCollection);
                    context.addConstraint(securityConstraint);
                }
            };
            factory.addAdditionalTomcatConnectors(redirectConnector());
            return factory;
        }
    
        private Connector redirectConnector() {
            Connector connector = new Connector(Http11NioProtocol.class.getName());
            connector.setScheme("http");
            connector.setPort(8100);
            connector.setSecure(false);
            connector.setRedirectPort(443);
            return connector;
        }
    }
    

      修改配置文件

    server:
      ssl:
        key-store: classpath:ssl/2833975_www.renyimao.cn.pfx
        key-store-password: KzwpacCY
        keyStoreType: PKCS12
      port: 443 #启动端口

      文件目录

  • 相关阅读:
    windows10关闭更新,windowsUpdate禁用无效 windows无限重启 一分钟无限重启 win10无法连接到SENS服务
    Visual Studio项目/解决方案重命名
    关于Geometry中的一些简单形状
    无法打开http://localhost:6080/arcgis/manager/
    centOS无法联网
    FTP服务器搭建
    iFrame中dateGrid中数据不显示
    关于python的基础知识
    python中int str bool list dict数据操作方法汇总
    关于int str bool的讨论
  • 原文地址:https://www.cnblogs.com/xiaojf/p/11626500.html
Copyright © 2011-2022 走看看