tomcat安装pfx格式的SSL证书

发布时间:2019/8/29 21:22:39 打印 字号:

从tomcat 7开始支持使用pfx格式的SSL证书安装,这种安装方式相对简单一些,如果你的证书格式是pem格式的,要先转换为pfx格式的后才能安装
可以使用我们的在线证书格式转换工具:https://www.gworg.com/tools/

或者 使用如下命令 

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

其中 certificate.crt  是CA颁发的服务器证书,privateKey.key 是密钥(Key),CACert.crt是中级证书  ,certificate.pfx  是转换后得到的证书,
其中 privateKey.key  certificate.crt  CACert.crt 这三个文件可以是pem ,txt 或 crt 后缀的文件。


有了certificate.pfx这个证书后,下面就可以开始安装了,找到安装 Tomcat 目录下该文件server.xml,一般默认路径都是在 conf 文件夹中。找到 <Connector port="8443" 标签,增加如下属性

keystoreFile="certificate.pfx"
keystoreType="PKCS12"
keystorePass="certificate.pfx证书的密码"

其中/path/cert.pfx替换成你的证书所在位置,keystorePass是pfx格式证书的密码。
修改后:

<Connector port="8443" protocol="HTTP/1.1"
    maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
    keystoreFile="/path/certificate.pfx"
    keystoreType="PKCS12"
    keystorePass="certificate.pfx证书的密码"
    clientAuth="false"
   sslProtocol="TLS"
   ciphers="TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
   TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
  TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,  
  TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
  TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
  TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
  TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,
  TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
  TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,
  TLS_DHE_RSA_WITH_AES_256_CBC_SHA,
  TLS_RSA_WITH_AES_128_GCM_SHA256,
  TLS_RSA_WITH_AES_256_GCM_SHA384,
  TLS_RSA_WITH_AES_128_CBC_SHA256,
  TLS_RSA_WITH_AES_256_CBC_SHA256,
  TLS_RSA_WITH_AES_128_CBC_SHA,
  TLS_RSA_WITH_AES_256_CBC_SHA,
  SSL_RSA_WITH_3DES_EDE_CBC_SHA" />

修改完成,重启tomcat 就可以了。