Tomcat SSL配置大全
由于配置CAS的单点登陆系统,需要先配置 Tomcat 的SSL, 在配置tomcat的SSL过程中,我配置的版本是tomcat5.5.20,参考了很多资料,但发现一直不行,后来我换到了5.5.9,结果非常顺利, 我于是换了总共4个主要版本,发现SSL的配置还真有些不同,现在我将这些配置记录下来,供下次参考。
参考文档
Keytool 使用指南:
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/keytool.html
Tomcat-ssl 配置指南:
http://tomcat.apache.org/tomcat-5.5-doc/ssl-howto.html
配置过程
以命令行方式切换到目录%TOMCAT_HOME%,在command命令行输入如下命令(jdk1.4以上带的工具):
keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass changeit -keystore server.keystore -validity 3600
用户名输入域名,如localhost(开发或测试用)或hostname.domainname(用户拥有的域名),其它全部以 enter 跳过,最后确认,此时会在%TOMCAT_HOME%下生成server.keystore 文件。
注:参数 -validity 指证书的有效期(天),缺省有效期很短,只有90天。
2. 将证书导入的JDK的证书信任库中:
这步对于T omcat的SSL配置不是必须,但对于CAS SSO是必须的,否则会出现如下错误:edu.yale.its.tp.cas.client.CASAuthenticationException: Unable to validate ProxyTicketValidator。。。
导入过程分2步,第一步是导出证书,第二步是导入到证书信任库,命令如下:
keytool -export -trustcacerts -alias tomcat -file server.cer -keystore server.keystore -storepass changeit
keytool -import -trustcacerts -alias tomcat -file server.cer -keystore %JAVA_HOME%/jre/lib/security/cacerts -storepass changeit
如果有提示,输入Y就可以了。
其他有用keytool命令(列出信任证书库中所有已有证书,删除库中某个证书):
keytool -list -v -keystore D:/sdks/jdk1.5.0_11/jre/lib/security/cacerts
keytool -delete -trustcacerts -alias tomcat -keystore D:/sdks/jdk1.5.0_11/jre/lib/security/cacerts -storepass changeit
3. 配置TOMCAT :
修改%TOMCAT_HOME%\conf\server.xml,以文字编辑器打开,查找这一行:
Tomcat4.1.34 配置:
xml 代码
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
port="8443" minProcessors="5" maxProcessors="75"
enableLookups="true"
acceptCount="100" debug="0" scheme="https" secure="true"
useURIValidationHack="false" disableUploadTimeout="true">
<Factory className="org.apache.coyote.tomcat4.CoyoteServerSocketFactory"
clientAuth="false" protocol="TLS"
keystoreFile="server.keystore" keystorePass="changeit"
/>
</Connector>
Tomcat5.5.9 配置:
xml 代码
1.
2. < Connector port = "8443" maxHttpHeaderSize = "8192"
3. maxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
4. enableLookups = "false" disableUploadTimeout = "true"
5. acceptCount = "100" scheme = "https" secure = "true"
6. clientAuth = "false" sslProtocol = "TLS"
7. keystoreFile = "server.keystore"
8. keystorePass = "changeit" />
Tomcat5.5.20 配置 ( 此配置同样可用于 Tomcat6.0) :
xml 代码
1.
2. < Connector protocol = "org.apache.coyote.http11.Http11Protocol"
3. port = "8443" maxHttpHeaderSize = "8192"
4. maxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
5. enableLookups = "false" disableUploadTimeout = "true"
6. acceptCount = "100" scheme = "https" secure = "true"
7. clientAuth = "false" sslProtocol = "TLS"
8. keystoreFile = "server.keystore"
9. keystorePass = "changeit" />
Tomcat6.0.10 配置:
xml 代码
1. < Connector protocol = "org.apache.coyote.http11.Http11NioProtocol"
2. port = "8443" minSpareThreads = "5" maxSpareThreads = "75"
3. enableLookups = "true" disableUploadTimeout = "true"
4. acceptCount = "100" maxThreads = "200"
5. scheme = "https" secure = "true" SSLEnabled = "true"
6. clientAuth = "false" sslProtocol = "TLS"
7. keystoreFile = "D:/tools/apache-tomcat-6.0.10/server.keystore"
8. keystorePass = "changeit" />
tomcat6支持3种,请参考以下文档:
http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
验证配置
访问 https://localhost:8443/