/ 中存储网

Linux系统下Apache与Tomcat的整合安装配置过程

2013-09-24 17:46:01 来源:ITJS.CN
系统环境:

system:CentOS release 5.4 (Final)

httpd-2.2.14(/usr/local/apache2)

apache-tomcat-6.0.29(/usr/local/tomcat)

java-1.6.0_14(/usr/local/java6)

tomcat-connectors-1.2.37

下载地址

http://tomcat.apache.org/download-connectors.cgi

tar -xvf tomcat-connectors-1.2.37-src.tar.gz

cd tomcat-connectors-1.2.37-src/native/

./configure --with-apxs=/usr/local/apache2/bin/apxs

make

make install

 vi /usr/local/apache2/conf/httpd.conf

1.添加默认页面(index.jsp ,可不添加)

DirectoryIndex index.jsp index.html

2.添加如下文件

LoadModule jk_module          modules/mod_jk.so

Include /usr/local/apache2/conf/extra/mod_jk.conf

(切记在对应的位置,LoadModule和Include放置对应的地方)

[[email protected] htdocs]# vi /usr/local/apache2/conf/extra/mod_jk.conf

JkWorkersFile conf/extra/workers.properties

JkLogFile   logs/mod_jk.log

JkShmFile   logs/jk-runtime-status

JkLogLevel info

JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkRequestLogFormat "%w %V %T"

#Sample JkMounts.   Replace these with the paths you would

#like to mount from your JSP server.

#syntax: JkMount ${URL_DIR}/*.jsp worker_name

JkMount   /images/avatar/*     worker1

JkMount   /*.jsp worker1

JkMount /*.page worker1

JkMount /*.cic worker1

JkMount /func/* worker1

JkMount   /assets/*          worker1

JkMount   /remote/*          worker1

JkMount   /services/*        worker1

JkMount   /homebase/*        worker1

JkMount /skin/*      worker1

JkMount /error/*     worker1

JkMount /lib/*       worker1

JkMount /protected/*       worker1

JkMount /rounded/*       worker1

JkMount /FormOverLogin*       worker1

JkMount /fckeditor/editor/filemanager/connectors/*       worker1

JkMount /upload/image/*       worker1

简要说明:

###JkWorkersFile conf/extra/workers.properties

指出mod_jk模块工作所需要的工作文件workers.properties的位置

###JkLogFile   logs/mod_jk.log

放置jk logs的位置

###JkLogLevel info

Set the jk log level [debug/error/info]

###JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

Select the log format

###JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

JkOptions indicate to send SSL KEY SIZE,

###JkRequestLogFormat "%w %V %T"

 JkRequestLogFormat set the request format

###JkMount..xx…worker1

..xx…请求通过ajp13的协议送给Tomcat,让Tomcat来处理

Set the jk log level [debug/error/info]

[[email protected] htdocs]# vi /usr/local/apache2/conf/extra/workers.properties

worker.list=worker1    

worker.worker1.port=8009

worker.worker1.host=localhost

worker.worker1.type=ajp13

worker.woker1.lbfactor=1

tomcat修改web路径与apahce保持一致

在<Host></Host>之间添加

<Context path="" docBase="/usr/local/apache2/htdocs/" debug="0" reloadable="true" crossContext="true" />

启动Apache:

#/usr/local/apache2/bin/apachectl   start

启动tomcat:

#/usr/local/tomcat/bin/startup.sh    start

编写简单jsp界面测试apache是否支持jsp页面(/usr/local/apache2/htdocs):

index.jsp

<html>

<body>

<h1>JSP Test Page</h1>

<%=new java.util.Date()

%>

</body>

</html>

返回正常()

JSP Test Page

Wed Jun 20 16:43:13 CST 2012

方法二:

在 /usr/local/apache2/conf/httpd.conf  末尾加入 :

<Proxy balancer://localCluster>

BalancerMember ajp://localhost:8009

</Proxy>

RewriteEngine On

ProxyPreserveHost On

RewriteRule ^/$ balancer://localCluster/ [P,L,NC]

RewriteRule ^/(.*)$ balancer://localCluster/$1 [P,L,NC]

然后修改tomcat web路径 同上即可!