服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

快速教您apache + tomcat + ssl的配置

运行环境:windows2003 server sp4 + j2sdk1.5.0 + apache2.0.54 + tomcat5.5.9

准备软件:

1.安装 apache 2.0.54

2.tomcat 5.5.14

3.jk2连接器(mod_jk2.so)

一、配置apache和tomcat

apache安装在d:\apache2 下,监听端口 80;

tomcat在d:\tomcat51 下,监听端口 8080;

两者都以windows 2000服务进行安装。

将mod_jk2.so复制到d:\apache2\modules目录下:

1.编辑d:\apache2\conf\httpd.conf文件,在loadmodule那一段代码中添加:

loadmodule jk2_module modules/mod_jk2.so

2.将adddefaultcharset iso-8859-1 改为 adddefaultcharset gb2312 使apache自动支持中文显示;

3.在“虚拟主机配置代码段”中添加:(此段配置可以根据你的实际情况进行修改)

<virtualhost *:80> 
serveradmin linvsfen◎163.com documentroot "d:/ tomcat51/webapps/jsp-examples
servername localhost errorlog logs/error_log customlog logs/access_log common 
</virtualhost>

编写workers2.properties文件并加入d:\apache2\conf目录,内容如下:

# usually commented out onproduction environments[logger.apache2]file=”
d:/apache2/logs/error.log”level=error# provide the basic config needed[config]
file=d:/apache2/conf/workers2.propertiesdebug=1# provide the location of shm file 
on the apache web server[shm]file=d:/apache2/conf/jk2.shmsize=1000000
[channel.socket:localhost:8009]port=8009host=localhost#define the worker
[ajp13:localhost:8009]channel=channel.socket:localhost:8009# map the tomcat 
examples webapp to the web server uri space [uri:/jsp-examples/*][uri:/*.jsp]

编写一个jsp文件(sessiontest.jsp),放在d:\tomcat51\webapps\jsp-examples 下;重新启动以后,启动apache和tomcat,访问http://localhost/jsp-examples/sessiontest.jsp可以访问。

二、tomcat配置上ssl步骤:

1. 生成服务器证书server02.jks和客户端证书dwp.p12

2. 把server02.jks放到conf目录下,打开d:\ tomcat51\conf\server.xml 文件,

然后修改server.xml文件,将注释掉的内容的注释去掉和增加证书存放的位置:如下:

<connector port="8443" maxhttpheadersize="8192"maxthreads="150" minsparethreads="25"
maxsparethreads="75"enablelookups="false" disableuploadtimeout="true"acceptcount="100" 
scheme="https"secure="true"clientauth="true" sslprotocol="tls" 
keystorefile="conf\server02.jks" 
keystorepass="123456" truststorefile="conf\server02.jks" 
truststorepass="123456"/>

注:server02.jks是证书存贮文件

安装客户端证书dwp.p12

3. 修改tomcat配置,使其自动启用ssl

打开d:\test\tomcat51\webapps\jsp-examples\web_inf\web.xml 文件,在security-constraint 标签下,增加如下内容:

<user-data-constraint> 
<description>
constrain the user data transport for the whole application 
</description> 
<transport-guarantee> confidential </transport-guarantee>
</user-data-constraint> 
<!--注释掉<auth-constraint>标签下的内容-->
<auth-constraint> 
<!-- anyone with one of the listed roles may access this area --> 
<role-name>tomcat</role-name> 
<role-name>role1</role-name> 
</auth-constraint>
<!--在web-resource-collection 标签下,增加如下内容:-->
<url-pattern>/*</url-pattern>

重新启动apache和tomcat,访问 http://localhost/jsp-examples/sessiontest.jsp是可是访问的,这是系统提示用户出示证书,启用ssl加密通道,ssl建立后,返回结果。url变为https://localhost:8443/jsp-examples/sessiontest.jsp

扫描关注微信公众号