---
title: "Tomcat下配置SSL"
author: "bearjava"
date: "2008-04-29T17:18:35Z"
tags: []
slug: "tomcat-ssl"
draft: false
lastmod: "2008-12-07T12:00:38Z"
id: 188121
url: "https://bearjava20071220091900.iteye.com/blog/188121"
---

**1.运行jdk下的命令:**
keytool -genkey -keyalg RSA -alias youraliasname -keystore .keystore

输入keystore密码：  000000
您的名字与姓氏是什么？
  ：  xy
您的组织单位名称是什么？
  ：  hdhr
您的组织名称是什么？
  ：  hdhr
您所在的城市或区域名称是什么？
  ：  tianjin
您所在的州或省份名称是什么？
   ：  tianjin
该单位的两字母国家代码是什么
  ：  CN
CN=xy, OU=hdhr, O=hdhr, L=tianjin, ST=tianjin, C=CN 正确吗？
    输入:y 
输入<CidSoftKey>的主密码
        （如果和 keystore 密码相同，按回车）：需要按回车

**2.将key文件copy到tomcat的conf下.**

**3.然后修改tomcat的conf下的server.xml文件，把8443端口改为如下配置：**  

```xml

    <Connector port="8443" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" disableUploadTimeout="true"
               acceptCount="100" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" 
               keystoreFile="conf/.keystore" keystorePass="000000"/>

```

 
**4.项目的web.xml文件中定义SSL安全链接:**

```xml

<security-constraint>   
    	<web-resource-collection >   
	          <web-resource-name >iArt</web-resource-name>  
	          	<url-pattern>/checkOut.action</url-pattern>   
   		  </web-resource-collection>   
      	<user-data-constraint> 
          	  <transport-guarantee>CONFIDENTIALtransport-guarantee</transport-guarantee>
 	</user-data-constraint>
 </security-constraint>

```


**5.如果项目使用struts2，在struts.properties中加入：**
struts.url.https.port = 8443   

**6.然后重起tomcat之后就可以访问了，当请求checkOut.action的时候将自动跳转到8443.**
**
7.手动把协议改成http即可恢复初态。**