Tomcat在启动HTTPS协议时遇到问题

问题描述 投票:2回答:1

我从GoDaddy获得了SSL证书,并在下面添加了在Keystore中添加证书:

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
keytool -import -alias intermed -keystore D:\ProgramFiles\apache-tomcat-6.0.45\conf\tomcat.keystore -trustcacerts -file D:\SSL_cert\intermed_cert\gdig2.crt
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文件中的连接器信息下面:

<Connector
 port="443"
 maxHttpHeaderSize="8192"
 maxThreads="150"    
 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/

但没有成功,并获得secure connection failed。 catalina日志中没有错误消息。而localhost:8080工作正常。通常的Tomcat主页加载在8080上。但8443根本没有工作。请检查以上步骤是否正确并提供帮助。

java tomcat ssl-certificate
1个回答
-1
投票

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

  1. 生成密钥库

首先,使用“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>
  1. 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.
  1. 完成保存并重启Tomcat,访问https://localhost:8443/

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

© www.soinside.com 2019 - 2024. All rights reserved.