tomcat服务器部分网页指定访问采用https协议

a、在tomcat安装目录下执行如下命令行:
keytool -genkey -alias tomcat -keyalg RSA -keypa
ss changeit -storepass changeit -keystore server.keystore -validity 3600
b、修改server.xml配置文件
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="server.keystore" 
               keystorePass="changeit"/>
c、重启tomcat,应用的url通过http和https协议均可以访问
d、如果仅需要限定部分url的访问必须通过https协议,需要在web.xml增加如下配置项。
<security-constraint>
<web-resource-collection>
<web-resource-name>must https</web-resource-name>
<url-pattern>/test1/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
这种配置情况下,web.xml所在应用的访问url一旦是以test1开头的,均会被强迫转向https访问

猜你喜欢

转载自fortaotao.iteye.com/blog/1184030