【发布时间】:2017-08-02 03:28:17
【问题描述】:
我正在 AWS EC2 实例的 8080 端口上运行 Spring Boot (Jhipster/Undertow) 应用程序。
我有一个配置为重定向的 AWS ELB
80 -> 8080
443 (SSL termination happens here) -> 8080
应用程序使用 Spring Security,如果您的用户到达 http://example.com,我希望它重定向到 https://example.com,以使用 SSL。
我在Tomcat 中找到了各种配置示例,但没有使用 Undertow。
我已经尝试过,使用第二个端口 8089,它会根据需要重定向,但这会导致端口 8080 也重定向我不想要的。
80 -> 8089
443 (SSL termination happens here) -> 8080
@Bean
public EmbeddedServletContainerFactory undertow() {
UndertowEmbeddedServletContainerFactory undertow = new UndertowEmbeddedServletContainerFactory();
undertow.addBuilderCustomizers(builder -> builder.addHttpListener(8089, "0.0.0.0"));
undertow.addDeploymentInfoCustomizers(deploymentInfo -> {
deploymentInfo.addSecurityConstraint(new SecurityConstraint()
.addWebResourceCollection(new WebResourceCollection()
.addUrlPattern("/*"))
.setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
.setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT))
.setConfidentialPortManager(exchange -> 443);
});
return undertow;
}
如何配置 Undertow 来实现这一点?
【问题讨论】:
-
twitter.com/ankinson/status/829256167700492288 是否可能与类似的问题有关,您想解决吗?
标签: spring-boot jhipster undertow