【问题标题】:Redirect http to https on spring boot embedded undertow在嵌入undertow的spring boot上将http重定向到https
【发布时间】:2015-08-19 03:26:00
【问题描述】:

我使用的是 spring boot (1.2.3) 和嵌入式 undertow。出于安全原因,我更愿意将任何 http 请求重定向到 https,但我找不到这样做的示例。

这里是 spring boot 和 tomcat 的示例: Spring boot - Embeded Tomcat HTTP to HTTPS redirect

有没有人用undertow解决这个问题?

【问题讨论】:

标签: java spring spring-boot undertow


【解决方案1】:

恕我直言,这是一个在 http 流量到达您的应用程序之前处理它的反向代理的问题。这对你来说是一个选择吗?

【讨论】:

    【解决方案2】:

    实际上,您将在 Spring Boot 应用程序中拥有 2 个端口,因此您必须创建另一个 EmbeddedServletContainerFactory,告诉新端口 http 或 https。创建新端口后,您可以使用 Spring Mvc 或 Spring Security 管理重定向。

    【讨论】:

      【解决方案3】:

      您可以将 Spring-Security 添加到您的项目中,然后配置 Spring-Security 以强制执行 https。您可以在

      的 JavaDoc 中找到一个小示例
      org.springframework.security.config.annotation.web.builders.HttpSecurity#requiresChannel()
      

      【讨论】:

      • 根据应该是解决方案的文档,但由于我们目前在 cloudfoundry 上运行,因此我使用此处指定的 http 标头实现了自定义过滤器:stackoverflow.com/questions/28227583/…
      猜你喜欢
      • 2017-08-02
      • 2014-12-13
      • 2015-03-11
      • 2014-12-26
      • 2019-09-21
      • 2016-10-13
      • 2019-05-15
      • 2021-03-31
      • 2021-12-12
      相关资源
      最近更新 更多