第一步:
用java自帶的工具生成證書
keytool -genkey -v -alias tomcat -keyalg RSA -keystore C:\apache-tomcat-8.5.31\conf\key\tomcat.keystore -validity 36500
第二步:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate
certificateKeystoreFile="cert/你的證書名稱.keyst"
certificateKeystorePassword="你的證書密碼"
certificateKeystoreType="PKCS12"
/>
</SSLHostConfig>
</Connector>
http和https互相轉換
<!-- 配置http 自動轉爲 https -->
<security-constraint>
<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>