tomcat7.0.55配置HTTP强制跳转到HTTPS

时间:2022-09-27 15:19:22

首先需要配置好HTTPS单向或双向链接

参考:

tomcat7.0.55配置单向和双向HTTPS连接(二)

然后编辑tomcat的conf目录下的web.xml

在<welcome-file-list>结束标签之后添加

    <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>

如下图所示

tomcat7.0.55配置HTTP强制跳转到HTTPS

然后重启tomcat,用浏览器打开

http://localhost:8080

地址栏能看到https://localhost:8443/说明配置成功