Tomcat SSL 配置

来源:互联网 发布:sql文件解压后怎么安装 编辑:程序博客网 时间:2024/06/07 12:23

Using JDK 7 and Tomcat 7, similar to other versions.

Step:

1. 用Java去创建一个keystore文件,执行 keytool genkey - alias tomcat - keyalg RSA.

因此在用户主目录,创建了一个keystore文件。

C:\Users\calvin.yang>keytool -genkey -alias tomcat -keyalg RSAEnter keystore password: password Re-enter new password: passwordWhat is your first and last name?[Unknown]: calvin yangWhat is the name of your organizational unit?[Unknown]: abcWhat is the name of your organization?[Unknown]: abcWhat is the name of your City or Locality?[Unknown]: ZhuhaiWhat is the name of your State or Province?[Unknown]: GuangDongWhat is the two-letter country code for this unit?[Unknown]: CNIs CN=calvin yang, OU=abc, O=abc, L=Zhuhai, ST=GuangDong, C=CN correct?[no]: yesEnter key password for <tomcat>(RETURN if same as keystore password): passwordRe-enter new password: password

2. 配置Tomcat,使用这个keystore文件

打开server.xml,找到下面的注解

<!--<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"    maxThreads="150" scheme="https" secure="true"    clientAuth="false" sslProtocol="TLS" />-->
去掉注释,改变成下面的内容
<Connector SSLEnabled="true" acceptCount="100" clientAuth="false"    disableUploadTimeout="true" enableLookups="false" maxThreads="25"    port="8443" keystoreFile="C:/Users/calvin.yang/.keystore" keystorePass="password"    protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"    secure="true" sslProtocol="TLS" />
3. 测试

开启Tomcat,访问https://localhost:8443. 你就会看见Tomcat的默认主页面了。

4.使用SSL配置应用程序, 例如:https://localhost:8443/myApp

打开web.xml,加上下面的配置:

<security-constraint>    <web-resource-collection>        <web-resource-name>securedapp</web-resource-name>        <url-pattern>/*</url-pattern>    </web-resource-collection>    <user-data-constraint>        <transport-guarantee>CONFIDENTIAL</transport-guarantee>    </user-data-constraint></security-constraint>
设置成 /* URL映射,你的程序的所有访问都会使用HTTPS。

设置transport-gurantee为CONFIDENTIAL,为了让程序支持SSL。如果你想要关掉SSL,你只要把CONFIDENTIAL变为NONE。


-------------------------------------------------------------------------------------------------

官方文档:http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html



原创粉丝点击