相信你们。
我的 web 应用程序在 tomcat 6.0.43 上运行,并且不在前端使用 apache 或 nginx。
我已经使用以下方法将我的网站从 http 重定向到 https:
- URL 重定向到 ../webapps/ROOT/index.jsp
<% response.sendRedirect("https://www.epi.com.my/portal/"); %>
- ../webapps/myapp/WEB-INF/web.xml
<security-constraint> <web-resource-collection> <web-resource-name>Protected Context</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint></security-constraint>
在下面哪里添加这样的代码
Header add Strict-Transport-Security "max-age=15768000"
或 难道tomcat没有这个功能? 或者我需要在我的每个 Java Web 应用程序 Controller 中进行修改。
最佳答案
如果您能够使用 Tomcat 7 或 8,则可以激活 built in HSTS filter .在 tomcat/conf/web.xml
httpHeaderSecurity
过滤器定义
<filter>
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<async-supported>true</async-supported>
</filter>
并添加一个有用的最大年龄参数:
<init-param>
<param-name>hstsMaxAgeSeconds</param-name>
<param-value>31536000</param-value>
</init-param>
不要忘记取消注释过滤器映射:
<filter-mapping>
<filter-name>httpHeaderSecurity</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
关于java - 为 Tomcat 添加 HSTS 特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27541755/