如何配置Tomcat以支持SSL或https

本文详细介绍如何在Tomcat6中配置SSL连接,包括生成自签名证书、修改server.xml文件及重启服务步骤,帮助读者实现https安全访问。

向您展示如何配置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>

2. 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"是您通过“ keytool ”命令分配给密钥库的密码。

3.完成

保存并重新启动Tomcat,访问https:// localhost:8443 /

tomcat-ssl-configuration

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

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

参考

  1. Tomcat 6:SSL配置指南

翻译自: https://mkyong.com/tomcat/how-to-configure-tomcat-to-support-ssl-or-https/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值