zoukankan      html  css  js  c++  java
  • 腾讯云服务器项目使用443端口

        使用腾讯云服务器,运行项目时,项目开启端口443

        

            同时实现80端口自动转为443端口代码:

    package com.jofiy.gaogao.config;
    
    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.beans.factory.annotation.Value;
    import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    public class CommonConfig {
        @Value("${http.port}")
        private Integer httpPort;
        @Value("${server.port}")
        private Integer serverPort;
    
        @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;
        }
    
        @Bean
        public Connector httpConnector() {
            Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
            connector.setScheme("http");
            //Connector监听的http的端口号
            connector.setPort(httpPort);
            connector.setSecure(false);
            //监听到http的端口号后转向到的https的端口号
            connector.setRedirectPort(serverPort);
            return connector;
        }
    }

    然后打包,部署项目至服务器,运行,一直报错

     直到使用安装nginx排查一下问题时,找到一篇文章这样说:sudo su root ,

      

    再次运行项目:问题得到解决

        

      

  • 相关阅读:
    json字符串数组判断其中
    json字符串数组判断其中
    jquery select chosen禁用某一项option
    数据库培训知识
    人员管理模块代码总结2015/8/12整理
    正则表达式在STARLIMS中的应用总结
    控件属性表
    Form-公共代码
    Server-Script公共代码
    Celient-Script公共代码
  • 原文地址:https://www.cnblogs.com/focusHots/p/11891001.html
Copyright © 2011-2022 走看看