When using Tencent cloud server, run the project, the project open port 443
While achieving 80 ports automatically converted 443 Code:
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 listening http port number connector.setPort (httpPort ); connector.setSecure ( to false ); // listening to the port number to which a steering http https port number connector.setRedirectPort (the serverPort ); return Connector; } }
Then package, deploy projects to servers running, has been an error
Until use nginx install just the matter of the investigation, to find an article saying: sudo su root,
Run the project again: the problem is resolved