Spring boot Spring Boot 2设置重定向端口未重定向到8443
我的Spring Boot应用程序在使用端口8443时工作,但是http重定向到https只是部分工作,因为它确实将http重定向到https,但是没有重定向到端口8443。例如,domain.com重定向到https:example.com:8443,但不重定向到https:example.com:8443,因此不会添加端口号:8443,因此系统不会加载 MVC配置Spring boot Spring Boot 2设置重定向端口未重定向到8443,spring-boot,https,Spring Boot,Https,我的Spring Boot应用程序在使用端口8443时工作,但是http重定向到https只是部分工作,因为它确实将http重定向到https,但是没有重定向到端口8443。例如,domain.com重定向到https:example.com:8443,但不重定向到https:example.com:8443,因此不会添加端口号:8443,因此系统不会加载 MVC配置 import org.apache.catalina.Context; import org.apache.catalina.c
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.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.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MvcConfig implements WebMvcConfigurer {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("login");
registry.addViewController("/login").setViewName("login");
}
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector(
TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
}
属性文件:
server.port: 8443
server.ssl.key-store:/etc/letsencrypt/live/fbt.systems.com/fbtkey.p12
server.ssl.key-store-password: ggggggggggg
server.ssl.keyStoreType: PKCS12
server.ssl.keyAlias: tomcat
POM
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
org.springframework.boot
spring引导启动器数据jpa
org.springframework.boot
弹簧启动启动器数据rest
org.springframework.boot
弹簧启动装置
org.springframework.boot
SpringBootStarterWeb
org.webjars
独自创立
3.3.4
org.webjars
jquery
3.1.0
org.springframework.boot
弹簧靴开发工具
运行时
mysql
mysql连接器java
运行时
org.springframework.boot
弹簧启动安全
org.springframework.security
弹簧安全性试验
测试
我希望运行应用程序而不必添加端口:8443,或者我希望http重定向自动添加端口号
请让我知道我将要做什么来调整上述一个或两个配置
问候
康泰康斯坦丁·斯坦利已经回答了这个问题,谢谢,但这个答案并不是自动添加端口号8443,这是我的问题。http到https重定向正在工作。