强制https访问,在浏览器中输入http的访问地址自动转换为https,端口问题

    xiaoxiao2021-03-26  29

    强制https访问,在浏览器中输入http的访问地址自动转换为https,端口问题

    强制https访问

      在tomcat\conf\web.xml中的</welcome-file-list>后面加上这样一段: Java代码 <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了

    例如:访问http://localhost/myproject/1直接调转为

    https://localhost/myproject/1  使用默认端口443 如果是其它端口 则跳转为https://localhost:8443/myproject/1

    需要注意的是:server.xml中http的转发端口要和SSL的端口一直

    tomcat\conf\server.xml

    SSL端口设置

    <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"                maxThreads="150" scheme="https" secure="true"                clientAuth="false" keystoreFile="c:/serv.jks" keystorePass="123456" sslProtocol="TLS" />

    <Connector port="80" protocol="HTTP/1.1"                 connectionTimeout="20000"                 redirectPort="443"   URIEncoding="GBK" useBodyEncodingForURI="true"/>

      redirectPort="443" 这个端口要和上面的SSL端口一致。

    443是https默认端口,

    转载请注明原文地址: https://ju.6miu.com/read-628666.html

    最新回复(0)