2017-03-11 38 views
1

我在AWS EC2实例上的端口8080上运行Spring引导(Jhipster/Undertow)应用程序。带有嵌入式Undertow的AWS Boot ELB - HTTPS重定向

我有一个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来实现此目的?

+0

https://twitter.com/ankinson/status/829256167700492288可能涉及类似的问题,你想解决? –

回答

0

这为我工作,当我有同样的问题:

揭露从jhipster端口80(你可以在application-prod.yml其更改)。

亚马逊ELB从HTTP重定向到https的时候增加了一些标题,你应该在同一个文件地址:

server: use-forward-headers: true port: 80

此外,您还需要从jhipster执行的https: https://jhipster.github.io/tips/007_tips_enforce_https.html