zoukankan      html  css  js  c++  java
  • spring boot 开启https

    1.生成证书

    keytool -genkey -alias tomcat -keyalg RSA -keystore E:/https.keystore
    

      

    将生成好的证书放在项目根目录即可

    2 修改配置文件

    server:
      port: 443
      servlet:
        context-path: /
      tomcat:
        uri-encoding: UTF-8
        max-threads: 1000
        min-spare-threads: 30
      ssl:
        #生成证书的名字
        key-store: https.keystore
        #密钥库密码
        key-store-password: 123456
        key-store-type: JKS
        key-alias: tomcat
    

     3 开启访问80端口跳转433端口

    package com.yjkj.repository;
    
    import org.apache.catalina.connector.Connector;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
    import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.Bean;
    
    @SpringBootApplication
    public class RepositoryApplication extends SpringBootServletInitializer {
    
        public static void main(String[] args) {
            SpringApplication.run(RepositoryApplication.class, args);
        }
    
        @Bean
        public ServletWebServerFactory servletContainer() {
            TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
            tomcat.addAdditionalTomcatConnectors(createHTTPConnector());
            return tomcat;
        }
    
        private Connector createHTTPConnector() {
            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            //同时启用http(80)、https(8443)两个端口
            connector.setScheme("http");
            connector.setSecure(false);
            connector.setPort(80);
            connector.setRedirectPort(443);
            return connector;
        }
    }

    https访问

      

    http访问

  • 相关阅读:
    LeetCode Notes_#328_奇偶链表
    LeetCode Notes_#203_移除链表元素
    LeetCode Notes_#19_删除链表的倒数第N个节点
    如何选择分类模型的评价指标
    利用类权重来改善类别不平衡
    使用LIME解释黑盒ML模型
    Python机器学习算法:线性回归
    基于RNN自编码器的离群点检测
    用TensorFlow预测纽约市AirBnB租赁价格
    权重不确定的概率线性回归
  • 原文地址:https://www.cnblogs.com/joyny/p/11309584.html
Copyright © 2011-2022 走看看