使用 JSSE 配置

发送反馈


使用 JSSE 方式配置 HTTPS 加密有如下步骤:

  1. 生成服务器证书(公钥)

Windows:

%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA -keystore D:\key.keystore

Unix:

$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA -keystore /home/key.keystore

其中,-keystore 参数指定的是证书的存放位置,可以任意指定。

按照提示输入密码(部署时 Tomcat 默认使用“changeit”作为密码),如“123456”,输入相关信息后确认。

  1. 修改 server.xml 配置文件,开启 SSL

注释掉如下配置,不使用 APR:

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

找到 SSL HTTP/1.1 Connector 的配置,即:

<!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the 
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
        …
-->

去掉注释,修改如下:

<Connector port="8443" protocol="HTTP/1.1"
                   SSLEnabled="true"
                   maxThreads="150"
                   scheme="https"
                   secure="true"
                   URIEncoding="utf-8"
                   clientAuth="false"
                   keystoreFile="D:\key.keystore"
                   keystorePass="123456"
                   sslProtocol="TLS"/>
  1. 重启 Tomcat,即可在8443端口通过 HTTPS 访问 Web 应用,如 https://localhost:8443/iserver/manager 。