您的位置:首页 > 理论基础 > 计算机网络

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

2013-05-22 09:48 751 查看
参考: http://hengstart.iteye.com/blog/840265
强制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默认端口,
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: