zoukankan      html  css  js  c++  java
  • Tomcat SSL配置 Connector attribute SSLCertificateFile must be defined when using SSL with APR解决

    Tomcat 6版本配置SSL过程有两步:

    1、用JDK自带的keytool.exe来生成私有密钥和自签发的证书,如下:

    keytool -genkey -keyalg RSA -alias tomcat

    按提示输入相关内容后,这条命令将在默认密钥库文件里新增一个别名为tomcat的私有密钥项及其自签发的证书。默认密钥库文件为:

    %USERPROFILE%.keystore

    2、修改Tomcat的confserver.xml文件,即增加下面一段:

        <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS"
                   keystoreFile="${user.home}/.keystore"
                   keystorePass="changeit" />

    这里的${user.home}就是上面的%USERPROFILE%,只是一个是Java语法,另一个是Windows语法。

    设置好就能正常启动Tomcat了。

    可是按同样的方法来配置Tomcat 7却启动不起来,报如下错误:

    严重: Failed to initialize end point associated with ProtocolHandler ["http-apr-8443"]
    java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR

    仔细看上面的异常信息发现这是APR报的错误。Tomcat 6也有APR包但我从来都没用过。为此查看了Tomcat的ssl-how,在“Edit the Tomcat Configuration File”一节中说到:

    • Tomcat提供了两个SSL实现,一个是JSSE实现,另一个是APR实现。
    • Tomcat将自动选择使用哪个实现,即如果安装了APR则自动选择APR,否则选择JSSE。
    • 如果不希望让Tomcat自动选择,而是我们自己指定一个实现则可通过protocol定义,如下:
    <Connector protocol="..." />

    我又查看了6.0的相同说明,里面与7.0的说明一模一样。因此问题只可能是:是否安装了APR包。

    以前只听说过APR但没弄过。APR是什么文件?后来才发现APR文件名为tcnative-1.dll。进一步检查6.0和7.0的安装目录,结果发现6.0里没这个dll文件,而7.0里有。换句话说,6.0默认使用JSSE实现,而7.0默认使用APR实现。

    弄明白缘由就好办了。由于习惯使用6.0的配置方式(即JSEE实现),因此只要把上面confserver.xml里的protocol修改一下就行了:

        <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS"
                   keystoreFile="${user.home}/.keystore"
                   keystorePass="changeit" />

     重新启动,一切正常。

  • 相关阅读:
    sql分页查询
    SQL语句优化技术分析
    大型数据库的设计原则与开发技巧
    Microsoft SharePoint Server 2010 的新增功能
    Installing SharePoint 2010 on Windows 7
    Missing the ManageContent and structure in MOSS 2010
    Simple SharePoint 2010 + Silverlight + Client Object Model Example
    SharePoint 2010 Central AdminCreate/Extend Web Application button on Ribbon are disabled
    利用SharePoint Designer 修改列表页面实例
    数据库设计中的14个技巧
  • 原文地址:https://www.cnblogs.com/fengmao/p/8080111.html
Copyright © 2011-2022 走看看