Win2K下Apache2+TomCat5.0整合解决方案

Win2K下Apache2+TomCat5.0整合解决方案
Win2K下Apache2.0+TomCat5.0解决方案
  
操作系统:windows 2000 professional 中文版+sp4
java 环境:j2sdk1.4.2_01 JAVA_HOME= C:/j2sdk1.4.2_01
apache 2.0.48 for win32:apache_2.0.48-win32-x86-no_ssl.msi下载地址
http://archive.apache.org/dist/httpd/
tomcat 5.0.16 for win32:jakarta-tomcat-5.0.16.exe下载地址
http://jakarta.apache.org/site/binindex.cgi
jk2 模块 for win32: mod_jk2-2.0.43.dll 下载地址
http://apache.scarlet.be/jakarta/tomcat-connectors/jk2/binaries/win32/
以上软件的下载网址: http://www.apache.org
1.    安装并测试Apache和TomCat5.0;
注意事项: Apache默认端口为80,与IIS冲突,更改端口或关闭IIS,
TomCat安装完后配置环境变量。
2.    开始整合;
首先,将文件mod_jk2.so 复制到Apache 的模块目录(%Apache%/Apache2/modules)中。
备份Tomcat 和Apache 的缺省配置文件,以防不测。
其次,编辑配置文件。具体的配置文件有四个,
它们分别是:httpd.conf、jk2.properties、server.xml、workers2.properties。

a、 修改ApacheRoot/Apache2/conf/httpd.conf 文件
1>修改web 主目录,即将
DocumentRoot "D:/websrv/Apache2/htdocs" 改为自己的web主目录
eg:     DocumentRoot    "D:/websrv/myweb"
2>修改web 主目录对应的目录,即将
<Directory "D:/websrv/Apache2/htdocs">改为
eg:     <Directory "D:/websrv/myweb" >
此目录块要与DocumentRoot的路径对应,块中的语法是对此块对应Web主目录的操作权限设置。
3>修改目录缺省的web 文件,即将
DirectoryIndex index.html index.html.var 改为
eg:      DirectoryIndex index.html index.html.var index.jsp
语法说明:当向Apache 发出请求时容器将顺次去找index.html,如果没有,将接着找index.htm,最后找index.jsp。
4>修改cgi-bin 所在目录,即将
ScriptAlias /cgi-bin/ "D:/websrv/Apache2/cgi-bin/"改为
ScriptAlias /cgi-bin/ "D:/websrv/myweb/cgi-bin/"
<Directory "D:/websrv/Apache2/cgi-bin"> 改为
<Directory "D:/websrv/myweb/cgi-bin">
如果程序中需要用到cgi时修改以上两处。
5>添加指定的虚拟目录(别名),及其对应目录的属性
#这是测试用的文件夹,能执行jsp 文件。
Alias  /jj/           "D:/websrv/myweb/jj/"
<Directory       "D:/websrv/myweb/jj" >
AllowOverride None
Options IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
</Directory>

     Alias  /chengxin/     "D:/websrv/myweb/chengxin/"
     <Directory              "D:/websrv/myweb/chengxin" >
        AllowOverride None
       Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
       Allow from all
     </Directory>
#在web主目录myweb中添加了两个测试应用程序jj和chengxin
语法说明:
 
      Alias  /web程序别名/     "程序根目录/"                            ##别忘啦最后有/
      <Directory              "程序根目录" >
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html                           对此程序的具体操作权限设置    
        AddHandler type-map var                                   
        Order allow,deny
       Allow from all
</Directory>
注意:
                   程序根目录必须和%Tomcat5%/conf/server.xml中配置的虚拟目录相吻合。
           6>修改缺省的字符集,使之支持中文,即将
AddDefaultCharset ISO-8859-1 改为
AddDefaultCharset GB2312
            7>在文件最后添加如下内容,以加载jk2 模块
<IfModule !mod_jk2.c>
LoadModule jk2_module modules/mod_jk2.so
</IfModule>

b、 修改Tomcat5Root/conf/jk2.properties 文件
在文件最后添加如下内容,打开shm 文件设置
#Shared memory directive
shm.file=ApacheRoot/Apache2/logs/jk2.shm
可以在ApacheRoot/Apache2/logs/下新建jk2.shm文件
c、 修改Tomcat5Root/conf/server.xml 文件
在apache 中对应指定的虚拟目录,server.xml 中也应指定,所以在
  <!-- Tomcat Root Context -->
<!--
<Context path="" docBase="ROOT" debug="0">
-->
的下面添加
<Context path="/jj" docBase="d:/websrv/myweb/jj" debug="0" reloadable="true"
crossContext="true"></Context>
<Context path="/chengxin" docBase="d:/websrv/myweb/chengxin" debug="0" reloadable="true"
crossContext="true"></Context>




d、 修改ApacheRoot/Apache2/conf/workers2.properties 文件
注意:如果此文件不存在,则在目录ApacheRoot /Apache2/conf 下新建一个。
添加如下内容
#***************************************************************************
# only at beginnin. In production uncomment it out 必须在文件开头定义
[logger.apache2]
level=DEBUG
#define the shared memory file 定义shm 文件
[shm]
file=ApacheRoot /Apache2/logs/jk2.shm    #指向Apache文件下的logs/jk2.shm文件
size=1048576
# Define the communication channel 定义信道
[channel.socket:localhost :8009]
tomcatId=localhost :8009
# define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
#jk2 的状况,可通过
http://localhost/status 查看
[status:]
info=Status worker, displays runtime information
channel=channel.socket:localhost:8009
# Uri mapping Uri 映射
#[uri:/path/*]会把
http://域名/path/里的所有请求发给tomcat。
#而[uri:/path/*.jsp]会把 http://域名/path 里的jsp 文件请求发给tomcat 处理。
#此path 可以是apache 的虚拟目录,也可以是tomcat 的虚拟目录,
#还可以是tomcat 的物理目录,这儿是配置jk2 的关键,试试就知道了。
[uri:/status/*]
worker=status:localhost:8009
group=status:
#[uri:/*]                ###表示web主目录下的所有请求都给TomCat处理
[uri:/jj/*.jsp]    ###表示web主目录下的jj程序中所有jsp文件请求都给TomCat处理
[uri:/chengxin/*]     ###表示web主目录下的changxin程序中所有请求都给TomCat处理
#[uri:/jsp/*.jsp]
worker=ajp13:localhost:8009
info=Map the whole webapp
注意:此文件中的8009端口设置必须与TomCatRoot/conf/server.xml文件中
       <Connector port="8009" 
               enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" />
对应。
到此已基本配置完成。

如果要通过配置虚拟主机的方法来访问还要进行以下配置:
 以下配置的是一个IP对应多个域名的方法。
1>    在apacheRoot/apache2/conf/httpd.conf修改
            Listen   80                                     #监听端口为80
#NameVirtualHost  *:80 为
NameVirtualHost 192.168.1.208:80
##################################Ip影射到程序主目
<VirtualHost 192.168.1.208:80>
#管理员Email
    ServerAdmin        webmaster@dummy-host.example.com
    #jj  web程序目录
DocumentRoot    d:/websrv/myweb/jj
#域名 
   ServerName         ccjg.test.com
  #日志
 ErrorLog          logs/dummy-host.example.com-error_log
    CustomLog       logs/dummy-host.example.com-access_log common
#多个域名对应一个程序是可以在此添加
ServerAlias   ccjg.test.gov.cn
#注意:
#每在ServerName或ServerAlias添加一个域名时相应的就应该在
#TomcatRoot/conf/server.xml文件中添加相应的<Host>块标记与之对应
#如果要在本机测试则在C:/WINNT/system32/drivers/etc/hosts须添加相应
#的IP对应于你的所设置域名,域名解析时用到
#eg:   192.168.1.208         ccjg.test.gov.cn
#           192.168.1.208         ccjg.test.com   
</VirtualHost>

<VirtualHost    192.168.1.208:80>
    ServerAdmin        webmaster@dummy-host.example.com
#chengxin  web程序目录
    DocumentRoot       d:/websrv/myweb/chengxin
    ServerName           chengxin.test.com
    ErrorLog                logs/dummy-host.example.com-error_log
    CustomLog             logs/dummy-host.example.com-access_log common
ServerAlias           ccjg.test.gov.cn
</VirtualHost>
以上是一个IP对应两个web程序。
2>    在TomCatRoot/conf/server.xml中添加对应的<Host>块
       <Host name="ccjg.test.com" debug="0" 
         appBase="d:/websrv/jj" 
         unpackWARs="true" autoDeploy="true"> 
        <Context path="" docBase="" debug="0"/> 
        <logger className="org.apache.catalina.logger.FileLogger" 
        directory="logs" prefix="cust1_log." suffix=".txt" 
        timestamp="true"/> 
</Host> 
<Host name="ccjg.test.gov.cn" debug="0" 
         appBase="d:/websrv/jj" 
         unpackWARs="true" autoDeploy="true"> 
        <Context path="" docBase="" debug="0"/> 
        <logger className="org.apache.catalina.logger.FileLogger" 
        directory="logs" prefix="cust1_log." suffix=".txt" 
        timestamp="true"/> 
        </Host>
到此OK

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值