Linux下Apache2+Tomcat5.0整合

服务器已有安装有Tomcat5.0和JDK1.4.2

Tomcat5.0目录:/home/oracle/tomcat

JDK 1.4.2目录:/home/oracle/j2sdk1.4.2_07

Tomcat5.0 和 JDK1.42 安装步骤略


安装Apache2.0.59至/home/oracle/apache

下载httpd-2.0.59.tar.gz上传至/home/oracle

cd /home/oracle

tar -zxvf httpd-2.0.59.tar.gz

cd httpd-2.0.59

#配置(prefix是安装路径,enable-mods-shared=all表示编译配置所有so文件)

./configure --prefix=/home/oracle/apache --enable-mods-shared=all

make

make install


#配置httpd.conf

vi /home/oracle/apache/conf/httpd.conf



ServerName 配置为 127.0.0.1,服务器IP或域名

DirectoryIndex 中添加index.htm index.jsp

DefaultLanguage 设置为zh-CN



cd /home/oracle/apache/bin



./apachectl start



打开 http://127.0.0.1/ 看见 "安装Apache的测试页面" 说明Apache已经安装成功



如果出现"403 Forbidden错误"(而且httpd.conf未设置不允许访问),解决方法如下:

不但要将WEB目录设置为可读,还要将WEB目录的所有父级目录设置为至少可检索



chmod +x /home

chmod +x /home/oracle

chmod +x /home/oracle/apache

chmod 777 -R /home/oracle/apache/htdocs



编译和设置mod_jk2



在 http://archive.apache.org/dist/jakarta/tomcat-connectors/jk2/ 中



下载jakarta-tomcat-connectors-jk2-src-current.tar.gz,放至/home/oracle



tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz



cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2



./buildconf.sh



./configure --with-apxs2=/home/oracle/apache/bin/apxs --with-java-home=/home/oracle/j2sdk1.4.2_07



make jk2-build-apxs



cd server/apache2



make -f Makefile.apxs install



成功执行完这几步骤之后,mod_jk2已经装好,接下来是配置阶段。



在/home/oracle/apache/conf目录下建立workers2.properties文件,内容如下



#---- worker2.properties



[logger.apache2]

level=DEBUG



# Shared memory handling. Needs to be set.

[shm]

file=/home/oracle/apache/logs/shm.file

size=1048576



# Example socket channel, explicitly set port and host.

[channel.socket:localhost:8009]

tomcatId=localhost:8009

port=8009

host=127.0.0.1

# define the worker

[ajp13:localhost:8009]

channel=channel.socket:localhost:8009



#[status:status]



# Uri mapping



#[uri:/jkstatus/*]

#group=status:status



#[uri:/jsp-examples/*]

#group=ajp13:localhost:8009



#[uri:/servlets-examples/*]

#group=ajp13:localhost:8009



#[uri:/javaapp/*]

#group=ajp13:localhost:8009



#[uri:www.home.net/*.jsp]

#worker=ajp13:localhost:8009



#[uri:10.0.0.10/*]

#worker=ajp13:localhost:8009



#[uri:/*.do]

#worker=ajp13:localhost:8009



[uri:/servlet/*]

worker=ajp13:localhost:8009



[uri:/*.jsp]

worker=ajp13:localhost:8009



#---- end of workers2.properties



然后在httpd.conf中添加虚拟目录


NameVirtualHost *

<VirtualHost *>

    ServerAdmin 123@126.com

    DocumentRoot /usr/website/123/webapps/ROOT

    ServerName www.123.com

    ErrorLog logs/123-error_log

    CustomLog logs/123-access_log common

    ErrorDocument 404 /error/404.html

    ErrorDocument 401 /error/401.html

</VirtualHost>


配置Tomcat中的conf/server.xml文件

更改Tomcat端口为8080,避免与apache冲突

分别在<Connector port="8080" 和<Connector port="8009" 中添加 URIEncoding="GBK",解决中文乱码


添加与Apache虚拟主机对应的Tomcat虚拟主机

<Host name= www.123.com  debug="0" appBase="/usr/website/123/webapps"

unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" > </Host>


至此,Linux下Apache2+Tomcat5整合成功!