gpt4 book ai didi

tomcat - Spring Boot 重定向到 https

转载 作者:行者123 更新时间:2023-11-28 23:25:15 27 4
gpt4 key购买 nike

我用的是centos 7,spring boot(用的是tomcat embedded)

在我的 application.properties 中

security.require-ssl=true
server.port: 8443

我可以通过

访问我的网站
www.xxxx.com

但是

xxxx.com

不工作

我也试过

在我的 application.properties 中

server.port: 8443

在应用类中

@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat
= new TomcatEmbeddedServletContainerFactory() {

@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(createHttpConnector());
return tomcat;
}

private Connector createHttpConnector() {
Connector connector
= new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setSecure(false);
connector.setPort(8080);
connector.setRedirectPort(8443);
return connector;
}

在日志中我看到

s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8443 (https) 8080 (http)

www.xxxxx.com 正在运行

xxxx.com自动转换为

xxxx.com:8443

我不明白为什么要添加端口。

最佳答案

可能禁用此指令可以避免端口重定向:

connector.setRedirectPort(8443);

但您必须考虑其他设置也有意义。

关于tomcat - Spring Boot 重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38193789/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com