站内搜索: 请输入搜索关键词

当前页面: 开发资料首页JSP 专题快速教您Apache + Tomcat + SSL的配置

快速教您Apache + Tomcat + SSL的配置

摘要: 快速教您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那一段代码中添加:

<table cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1> <tr> <td class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6>
LoadModule jk2_module modules/mod_jk2.so
</td></tr></table>


2.将AddDefaultCharset ISO-8859-1 改为 AddDefaultCharset GB2312 使Apache自动支持中文显示;

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

<table cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1> <tr> <td class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6>


    ServerAdmin linvsfen◎163.com

    DocumentRoot

"d:/ Tomcat51/webapps/jsp-examples

    ServerName localhost

    ErrorLog logs/error_log

    CustomLog logs/access_log common

  
</td></tr></table>


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

<table cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1> <tr> <td class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6>
# Usually commented out on

production environments

[logger.apache2]

file=”D:/Apache2/logs/error.log”

level=ERROR

# Provide the basic config needed

[config]

file=D:/Apache2/conf/workers2.properties

debug=1

# Provide the location of shm

file on the Apache web server

[shm]

file=D:/Apache2/conf/jk2.shm

size=1000000

[channel.socket:localhost:8009]

port=8009

host=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]
</td></tr></table>


编写一个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文件,将注释掉的内容的注释去掉和增加证书存放的位置:如下:

<table cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1> <tr> <td class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6>
</td></tr></table>


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

安装客户端证书dwp.p12

3. 修改Tomcat配置,使其自动启用SSL

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

<table cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1> <tr> <td class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6>


      

Constrain the user data transport

for the whole application

      

      <transport-guarantee>

  CONFIDENTIAL

  </transport-guarantee>



 注释掉标签下的内容



        

 listed roles may access this area

         tomcat

     role1

      

在web-resource-collection 标签下,增加如下内容:

      /*
</td></tr></table>


重新启动Apache和tomcat,

访问 http://localhost/jsp-examples/sessiontest.jsp是可是访问的,这是

系统提示用户出示证书,启用SSL加密通道,SSL建立后,

返回结果。URL变为https://localhost:8443/jsp-examples/sessiontest.jsp

</td> </tr> <tr> <td vAlign=top align=left height="100%">
↑返回目录
前一篇: JSF导航文件如何设置实例解析
后一篇: 扩展 Hibernate 对各类数据源支持