1、使用keytool生成证书
keytool -genkey -alias test -keyalg RSA -keysize 1024 -keystore test.jks -validity 365
keytool -list -v -keystore test.jks
用来查看生成的证书
2、把证书加入到tomcat下
在tomcat下加入证书的方法
在tomcat 的conf/server.xml中
添加入证书的路径即可
<connector>
maxThreads="150" scheme="https" secure="true"
keystoreFile="conf/test.jks"
keystorePass="123456789"
clientAuth="false" sslEnabledProtocol="TLSv1,TLSV1.1,TLSv1.2" />
3、tomcat实现http自动跳转至 https
在/conf/web.xml 里添加配置
<security-constraint>
<web-resource-collection>
<web-resource-name>SSL/<web-resource-name>
<url-pattern>/*/<url-pattern>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL/<transport-guarantee>
然后再修改server.xml里面的重定向端口即可
修改重定向端口为443即可
閱讀更多 運維李小木 的文章