使用 APR 配置

发送反馈


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

1、在 OpenSSL 网站(http://www.openssl.org/)下载 OpenSSL,在 Window 平台下可使用 OpenSSL for Windows。

2、利用 OpenSSL 生成公钥和私钥。

a) 将 OpenSSL 的 bin 目录添加到系统的 PATH 环境变量中 ,如 D:\OpenSSL-Win64\bin 。

b) 进入 OpenSSL>命令行,即在任意位置打开命令行窗口,输入如下命令:

openssl.exe

c) 为 Tomcat 创建一个私钥,执行如下命令行:

genrsa -des3 -out D:\tomcatkey.pem 2048

按照提示输入密码短语,例如“123456”,OpenSSL 会提示你重复输入一次确认。然后会生成一个名为 tomcatkey.pem 的私钥,D:\tomcatkey.pem 为该私钥的路径。

d) 创建一个使用该私钥的证书

创建私钥后,还需要创建一个证书,在 OpenSSL>命令行执行如下命令:

req -new -x509 -key D:\tomcatkey.pem -out D:\tomcatcert.pem -days 1095

按照提示输入 tomcatkey.pem 的密码短语,这里为“123456”(创建私钥时指定),并输入相关信息后,即生成一个周期为3年(1095天)的自签名证书,即 tomcatcert.pem,tomcatcert.pem 使用 tomcatkey.pem 这个私钥,D:\tomcatcert.pem 为该证书的路径。

3、修改 server.xml 配置文件,开启 SSL。

a) 找到 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"
                   SSLCertificateFile="D:\tomcatcert.pem"
                   SSLCertificateKeyFile="D:\tomcatkey.pem"
                   SSLPassword="123456"
                   sslProtocol="TLS"/>

4、重启 Tomcat,即可在 8443 端口通过 HTTPS 访问 Web 应用,如 https://localhost:8443/iserver/manager 。