1、使用keytool生成證書
keytool -genkey -alias test -keyalg RSA -keysize 1024 -keystore test.jks -validity 365
![linux下生成jks證書並實現跳轉https](http://p2.ttnews.xyz/loading.gif)
keytool -list -v -keystore test.jks
用來查看生成的證書
2、把證書加入到tomcat下
在tomcat下加入證書的方法
![linux下生成jks證書並實現跳轉https](http://p2.ttnews.xyz/loading.gif)
在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即可
閱讀更多 運維李小木 的文章