1.让tomcat能使用https
A.在运行命令keytool -genkey -alias tomcat -keyalg RSA -keystore D:\tomcat.keystore
2.强制https访问
A.在运行命令keytool -genkey -alias tomcat -keyalg RSA -keystore D:\tomcat.keystore
B.打开tomcat目录下的server.xml文件并找到关于ssl的相关段
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="D:/tomcat.keystore" keystorePass="hanzhou"
clientAuth="false" sslProtocol="TLS" />
- keystoreFile:在第一步创建的key存放位置
- keystorePass:创建证书时的密码
2.强制https访问
在tomcat\conf\web.xml中的</welcome-file-list>后面加上这样一段:
<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了