首页 文章

tomcat不能使用HTTPS

提问于
浏览
2

我从goDaddy获得了SSL证书,并在下面添加了在Keystore中的证书 -

1. keytool -import -alias root -keystore D:\ProgramFiles\apache-tomcat-6.0.45\conf\tomcat.keystore -trustcacerts -file D:\SSL_cert\root_cert\gd_bundle-g2-g1.crt

2. keytool -import -alias intermed -keystore D:\ProgramFiles\apache-tomcat-6.0.45\conf\tomcat.keystore -trustcacerts -file D:\SSL_cert\intermed_cert\gdig2.crt

3. keytool -import -alias tomcat -keystore D:\ProgramFiles\apache-tomcat-6.0.45\conf\tomcat.keystore -trustcacerts -file D:\SSL_cert\tomcat_cert\7f5fa603b3815b70.crt

并在连接器信息下方添加 . 在tomcat server.xml文件中:

minSpareThreads =“25”maxSpareThreads =“75”enableLookups =“false”disableUploadTimeout =“true”acceptCount =“100”scheme =“https”secure =“true”SSLEnabled =“true”clientAuth =“false”sslProtocol =“TLS” keystoreFile =“D:\ ProgramFiles \ apache-tomcat-6.0.45 \ conf \ tomcat.keystore”keystorePass =“changeit”/>

在此之后我重新启动了tomcat服务器并试图这样做

https://localhost:8443/

但没有成功,安全连接失败 . catalina日志中没有错误消息 . 并且 localhost:8080 工作正常 . 通常的tomcat主页加载于 8080 . 但 8443 根本没有工作 . 请检查以上步骤是否正确并提供帮助 .

1 回答

  • 0

    一个指南,向您展示如何配置Tomcat 6.0以支持SSL或https连接 .

    • 生成密钥库

    首先,使用“keytool”命令创建自签名证书 . 在密钥库创建过程中,您需要分配密码并填写证书的详细信息 .

    $Tomcat\bin>keytool -genkey -alias mkyong -keyalg RSA -keystore c:\mkyongkeystore
    Enter keystore password:
    Re-enter new password:
    What is your first and last name?
      [Unknown]:  yong mook kim
    What is the name of your organizational unit?
      //omitted to save space
      [no]:  yes
    
    Enter key password for <mkyong>
            (RETURN if same as keystore password):
    Re-enter new password:
    
    $Tomcat\bin>
    

    在这里,您刚刚创建了名为“mkyongkeystore”的证书,该证书位于“c:\” .

    证书详细信息您可以使用相同的“keytool”命令列出现有证书的详细信息

    $Tomcat\bin>keytool -list -keystore c:\mkyongkeystore
    Enter keystore password:
    
    Keystore type: JKS
    Keystore provider: SUN
    
    Your keystore contains 1 entry
    
    mkyong, 14 Disember 2010, PrivateKeyEntry,
    Certificate fingerprint (MD5): C8:DD:A1:AF:9F:55:A0:7F:6E:98:10:DE:8C:63:1B:A5
    
    $Tomcat\bin>
    
    • server.xml中的连接器

    接下来,在$ Tomcat \ conf \ server.xml中找到Tomcat的服务器配置文件,通过添加连接器元素来修改它,以支持SSL或https连接 .

    文件:$ Tomcat \ conf \ server.xml

    //...
    <!-- 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"
                  maxThreads="150" scheme="https" secure="true"
                  clientAuth="false" sslProtocol="TLS"
               keystoreFile="c:\mkyongkeystore"
               keystorePass="password" />
     //...
    

    注意

    keystorePass="password" is the password you assigned to your keystore via “keytool” command.
    

    Tomcat的SSL的配置

    在此示例中,我们使用谷歌浏览器访问Tomcat配置的SSL站点,您可能会注意到在https协议:)之前出现了交叉图标,这是由自签名证书引起的,而Google Chrome只是不信任它 .

    在 生产环境 环境中,您应该考虑从受信任的SSL服务提供商(如verisign)购买签名证书,或使用您自己的CA服务器进行签名

    参考文献:https://www.mkyong.com/tomcat/how-to-configure-tomcat-to-support-ssl-or-https/ http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html

相关问题