一、 生成 server key :
以命令行方式切换到目录%TOMCAT_HOME%,输入如下命令:
keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass password -keystore server.keystore -validity 3600
参数-storepass中指定生成server key的个人密码,可以自行设置
参数 -validity 指证书的有效期(天),缺省有效期很短,只有90天。
参数 -keystore指定生成证书文件的名称
执行命令会提示输入信息,“您的名字与姓氏是什么?”这是必填项,并且必须是TOMCAT部署主机的域名或者IP[如:localhost 或者 127.0.0.1]否则浏览器会弹出警告窗口,提示用户证书与所在域不匹配。其他的可以直接回车,最后信息确认输入yes就会在%TOMCAT_HOME%目录下生成参数中指定的server.keystore文件。
二、修改tomcat配置文件
修改%TOMCAT_HOME%/conf/server.xml
找到文件中的如下配置,将注释去掉,keystoreFile、keystorePass两个参数。
keystoreFile是生成的server.keystore文件文件地址
keystorePass是-keystore参数指定的密码
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443
This connector uses the NIO implementation that requires the JSSE
style configuration. When using the APR/native implementation, the
OpenSSL style configuration is required as described in the APR/native
documentation -->
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="server.keystore"
keystorePass="password"/>
三、验证
访问https://localhost:8443