在 AWS ELB 后面带有嵌入式 Undertow 的 Spring Boot

编程入门 行业动态 更新时间:2024-10-27 08:24:51
本文介绍了在 AWS ELB 后面带有嵌入式 Undertow 的 Spring Boot - HTTP 到 HTTPS 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在 AWS EC2 实例的端口 8080 上运行 Spring Boot (Jhipster/Undertow) 应用程序.

I'm running a Spring boot (Jhipster/Undertow) application on port 8080 on an AWS EC2 instance.

我有一个配置为重定向的 AWS ELB

I have an AWS ELB configured to redirect

80 -> 8080 443 (SSL termination happens here) -> 8080

应用程序使用 Spring Security,如果您的用户到达 example 我希望它重定向到 example,使用 SSL.

The application uses Spring Security and if you user arrives to example I want it to redirect to example, to use SSL.

我在中找到了各种配置示例Tomcat 但没有使用 Undertow.

I have found various examples of configuring this in Tomcat but none using Undertow.

我已经尝试过这个,使用第二个端口 8089,它确实根据需要重定向,但这会导致端口 8080 也重定向我不想要的.

I have tried this, with a second port 8089, and it does redirect as required, but this causes port 8080 to also redirects which I don't want.

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 来实现这一点?

How can I configure Undertow to achieve this?

推荐答案

当我遇到同样的问题时,这对我有用:

This worked for me when I had the same problem:

从 jhipster 中暴露 80 端口(您可以在 application-prod.yml 中更改它).

Expose the port 80 from jhipster (you can change it in the application-prod.yml).

Amazon ELB 在从 http 重定向到 https 时添加了一些标头,您应该在同一文件中处理这些标头:

Amazon ELB when redirecting from http to https adds some headers, which you should address in the same file:

服务器:使用转发标题:true端口:80

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

Also, you need to enforce the https from jhipster: jhipster.github.io/tips/007_tips_enforce_https.html

更多推荐

在 AWS ELB 后面带有嵌入式 Undertow 的 Spring Boot

本文发布于:2023-11-01 19:46:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550237.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌入式   ELB   AWS   Boot   Spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!