【发布时间】:2021-08-27 13:43:09
【问题描述】:
我想为 http 打开端口 80,为 https 打开端口 433。 80端口应该重定向到433。我将application.properties中的服务器端口设置为80端口:
server.port=80
为了重定向,我遵循了官方的 spring 文档并创建了这个小类:
public class HTTPSRedirector {
@Bean
SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
http.redirectToHttps();
return http.build();
}
}
但是现在服务器超时了,当我尝试通过以下命令使用 curl 时:
curl -v http://www.example.com/
我收到Bad request 响应,因为启用了 SSL/TLS。如果我尝试像这样 ping / 联系 https 端口:
curl -v https://www.example.com/
然后我收到端口未打开且连接被拒绝的消息。如何在我的 Java spring 项目中同时打开 80 和 433 端口?
【问题讨论】:
-
stackoverflow.com/questions/30896234/… 另外,请确保您先在本地进行测试。如果您实际上正在使用甚至路由到网络外部的 FQDN 进行测试,那么请确保流量通过防火墙/路由器转发到您的 springboot 应用程序。如果您在本地运行 springboot 应用程序,请尝试 telnet 到端口 443 并查看它是否已打开(我认为这不是因为您只启用了端口 80,但在您显示的代码中没有 443 的连接器)
标签: java spring http https port