对于Tomcat服务器,如果需要支持使用https访问,可以将服务器证书生成以后,配置server.xml文件,开放https访问方式。但有些时候,可能我们需要将整站或者一些特定的URL限制为只能使用https方式进行访问,那么需要在WEB应用的web.xml文件中进行进一步的配置。
在 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>
完成以上步骤后,在浏览器中输入http的访问地址也会自动转换为https了
Tomcat配置HTTPS
如果Tomcat还未配置安装SSL证书,点击查看Tomcat安装SSL证书