【发布时间】:2021-03-01 10:49:28
【问题描述】:
我需要使用 HTTPS 在 2 个或更多端口上运行同一服务器。在早期生产中,我们为服务配置了 10500 端口。目前,我们需要在启用 SSL 的 443 和 10500 上运行它。
我找到了许多资源来为 Spring Boot 启用 HTTP 和 HTTPS。但我找不到任何允许在 2 个或更多端口上启用 HTTPS 服务的方法。
我已尝试配置端口重定向。但这也没有用。它在使用 HTTP 手动连接到端口 443 时有效。但是每当使用 HTTPS 时,程序都会抛出异常。
java.lang.IllegalArgumentException异常:无效字符在方法名实测值[0x160x030x010x020x000x010x000x010xfc0x030x030x810x00aC0x1b0x10`0xb80x8d0xae0x9e0xe40xc7V0xf60x08:e0xcc0x8f
@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(oldPortRedirectConnector());
return tomcat;
}
private Connector oldPortRedirectConnector() {
Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("https");
connector.setPort(443);
connector.setSecure(true);
connector.setRedirectPort(10500);
return connector;
}
application.properties
server.port=10500
非常感谢任何帮助。在 2 个端口上运行相同的服务或从一个 HTTPS 端口转发到另一个端口对我们来说真的很棒。
【问题讨论】:
-
这能回答你的问题吗? Configure Spring Boot with two ports
-
感谢您的建议。但这些答案仅提供配置额外 HTTP 端口的选项。我想要额外的 HTTPS 端口。
标签: java spring spring-boot