Tomcat SSL 配置

本文档介绍了如何在JDK 7和Tomcat 7环境下配置SSL。首先通过keytool生成keystore文件,然后在Tomcat的server.xml中解除注释SSL相关配置,启动Tomcat后,可以通过https://localhost:8443访问。此外,还说明了在web.xml中配置应用程序以支持SSL,将transport-guarantee设为CONFIDENTIAL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 RSA
Enter keystore password: password 
Re-enter new password: password
What is your first and last name?
[Unknown]: calvin yang
What is the name of your organizational unit?
[Unknown]: abc
What is the name of your organization?
[Unknown]: abc
What is the name of your City or Locality?
[Unknown]: Zhuhai
What is the name of your State or Province?
[Unknown]: GuangDong
What is the two-letter country code for this unit?
[Unknown]: CN
Is CN=calvin yang, OU=abc, O=abc, L=Zhuhai, ST=GuangDong, C=CN correct?
[no]: yes
Enter key password for <tomcat>
(RETURN if same as keystore password): password
Re-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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值