我需要在部署在 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/