tomcat - IBM Bluemix 在 spring boot 应用程序上强制执行 https(Jhipster 生成)

标签 tomcat https spring-boot ibm-cloud jhipster

我需要在部署在 IBM Bluemix 上的 spring-boot 应用程序(jhipster 生成)上强制执行 https。我正在部署没有嵌入式 tomcat 的 spring-boot war,cloudfoundry 的文档指定 java 构建包本身提供配置有 RemoteIPValve 的 Tomcat ,所以我不需要添加以下 header ,如 StackoverFlow 上的许多答案所指定的那样。

server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto

我还在安全配置中添加了以下代码

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.requiresChannel().anyRequest().requiresSecure();
}

我的应用仍然没有被重定向到 https。

我也曾怀疑,如果在 bluemix 域上执行 https,是否对自定义域也同样有效?

谢谢, 瓦苏

最佳答案

应用Yaml配置

服务器:

  tomcat:
     remote_ip_header: x-forwarded-for
     protocol_header: x-forwarded-proto

上面的tomcat headers告诉服务器原始请求是http还是https,

在 ResourceServerConfigurerAdapter 中 Overrides: configure(...) 的方法 configure(...) 中,我们必须添加以下行

if (profile.equalsIgnoreCase(Constants.SPRING_PROFILE_PRODUCTION)) { http.requiresChannel().anyRequest().requiresSecure(); }

关于tomcat - IBM Bluemix 在 spring boot 应用程序上强制执行 https(Jhipster 生成),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39729865/

相关文章:

http - 如何通过 telnet POST REQUEST 保存文件?

java - Spring Boot @WebMvcTest 中模拟方法返回值为 null

tomcat - 使用 Tomcat Cookbook 安装 tomcat7

jsp - 没有地址在使用时的tomcat Address already in use错误

asp.net - 页面位于大约 :blank displayed insecure content

java - 我可以在restTemplate.setErrorHandler 中包含restTemplate 请求正文吗?

mysql - hibernate中使用单表策略时将父类(super class)的实例更新为子类的实例

php - Windows 中的 Apache Web 服务器和 Tomcat

java - 以编程方式使用嵌入式 tomcat 7 配置 hibernate

ios - WKWebview 无法正确加载某些网站