http自动跳转https的安全配置
程序员文章站
2022-03-08 14:17:09
...
修改tomcat的相关配置
进入tomcat到conf目录下的web.xml。在后面,,也就是倒数第二段里,加上这样一段
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection>
<web-resource-name>SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
这步目的是让非ssl的connector跳转到ssl的connector去。所以还需要前往server.xml进行配置:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
redirectPort改成ssl的connector的端口443,重启后便会生效。