java - Spring Boot SSL 不会为所有人重定向 HTTP 到 HTTPS
问题描述
我已经使用 SSL 证书为我的网站设置了 HTTPS,一切似乎都运行良好,如果我输入 www.realmlands.com 它会将我重定向到 https:// 并且如果我删除 https:// 上的“s”并且点击输入它也会重定向到 https:// 但问题在于其他人,当他们去 www.realmlands.com 时它说不安全并且它不会让他们登录,因为它不是 https:// 但它应该重定向他们自动地。
我已经尝试过这种似乎大部分时间都可以使用的配置。
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
};
tomcat.addAdditionalTomcatConnectors(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector(
TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
connector.setScheme("https");
connector.setPort(8080);
connector.setSecure(true);
connector.setRedirectPort(443);
return connector;
}
它应该将每个人重定向到 https:// 但有些人认为不安全并被允许使用 http://
解决方案
推荐阅读
- pandas - AttributeError:“DataFrame”对象没有属性“Recovery”
- javascript - 如何遍历数字数组并将它们与具有相同ID的对象数组匹配
- flutter - 谷歌字体包在颤振中不起作用
- javascript - 如何在try catch中打破for循环
- handlebars.js - 是否可以在车把中扩展内联部分?
- laravel - 限制特定设备访问 Web 应用程序
- c# - 如何实现支持 Razor 和 Angular 的 ASP.NET Core 控制器?
- python - 在 python 中将大型 numpy-array 读取为 czi 文件
- c# - 依赖注入构造函数性能
- javascript - 需要帮助理解 Promise.all 和 async