tomcat7实现https访问及强制跳转到https

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/s295580857/article/details/80422844
tomcat实现https访问

首先在tomcat原来的配置文件中修改如下内容
原有配置:

<!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
-->

修改为:(注意这里我的证书文件214113519100202.pfx是放在tomcat目录下的cert目录里

<Connector port="443" protocol="HTTP/1.1"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
               keystoreFile="cert/214113519100202.pfx" keystorePass="输入你自己的证书密码"/>

然后重启tomcat,即可通过https://yourserverip:8443访问啦


强制跳转到https

这里非常简单,只需在tomcat目录下conf/web.xml文件中添加以下内容即可

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

重启tomcat后即可实现强制跳转到https。

猜你喜欢

转载自blog.csdn.net/s295580857/article/details/80422844