---
title: "Tomcat https(SSL) 简单的证书配置"
author: "CherryRemind"
date: "2010-03-08T15:33:11Z"
tags: ["JDK", "Java", "Tomcat", "Windows", "XML"]
categories: ["研发管理"]
slug: "tomcat-https-ssl"
draft: false
lastmod: "2010-03-08T15:33:11Z"
id: 610396
url: "https://todjiang.iteye.com/blog/610396"
---

参考\[url]http://confluence.atlassian.com/display/JIRA/Running+JIRA+over+SSL+or+HTTPS#RunningJIRAoverSSLorHTTPS-ImportCertificateIntoTheTruststore\[/url]，这个是配jira，但是差不多。 因为正式的CA申请要填什么东西，还要钱，很麻烦，如果我们只想在开发环境测试， 只要一个测试的证书用用就可以了，很多网上的sample不够详细，我记录下自己的研究。 我们一开始做的证书，用IE7访问的时候总是有个error, 看起来不舒服。后面解决这两个问题。 Windows环境，在CMD下输入 1.\[code="java"]"%JAVA\_HOME\\bin\\keytool" -genkey -alias tomcat -keyalg RSA\[/code] 当你敲入以上命令后， CMD提示输入 \[quote]What is your first and last name?\[/quote] 这时候，你\[b]必须\[/b]填写server ip或域名， 不是随便写的，否则后面生成的证书在IE7访问的时候， 会报一个"Mismatch Address"的Error. 后面的提示填的Unit, Dept, Country随便写写都无所谓的。 Tomcat默认的password是changeit,如果你写别的，在server.xml就要加入\[code="java"]keystorePass="xx"\[/code] 完了后，会生成文件\[quote]C:\\Documents and Settings\\xx\\keystore\[/quote] 2.\[code="java"]"%JAVA\_HOME\\bin\\keytool" -export -alias tomcat -file file.cer\[/code] 根据keystore信息生成一个证书 3.\[code="java"]"%JAVA\_HOME\\bin\\keytool" -import -alias tomcat -file file.cer -keystore "%JAVA\_HOME%\\jre\\lib\\security\\cacerts"\[/code] 讲生成的证书file.cer导入到Server JDK cacerts中。这个该死证书好像只能导入一次，重复导， 回报alias tomcat existed的错误。。 接下来是tomcat目录的server.xml配置 \[code="xml"]\[/code] 加入上面这段， 相当的简单， 因为都是默认的路径和P\[img]\[/img]assword, 所以没加\[quote]keystoreFile="xx" keystorePass="xx"\[/quote] 最后在浏览器certification需要安装到IE7，安装到"Trusted Root Certfication ..." \[img]http://dl.iteye.com/upload/picture/pic/56309/ef4ede52-13de-3d39-89a0-8e97519288c1.png\[/img] 访问https://xxIp/xxApp 就可以了。