Apache整合Tomcat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache整合Tomcat相关的知识,希望对你有一定的参考价值。

0.安装apache2.2

./configure --prefix=/usr/local/apache --enable-so \

--enable-rewrite --with-mpm=worker

make && make install


1.安装jdk

tar zxvf jdk-7-linux-i586.gz

mv jdk1.7.0 /usr/local/jdk

/usr/local/jdk/bin/java --version


2.安装tomcat7.0.37

tar zxvf apache-tomcat-7.0.37.tar.gz

mv apache-tomcat-7.0.37 /usr/local/tomcat

vim /etc/profile

export JAVA_HOME=/usr/local/jdk

export PATH=$PATH:JAVA_HOME/bin:/usr/local/apache/bin:/usr/local/tomcat/bin

export CLASSPATH=$JAVA_HOME/lib

source /etc/profile

/usr/local/tomcat/bin/catalina.sh start

netstat -an | grep :8080


3.Apache与Tomcat整合

(1).安装jk2

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

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

./configure --with-apxs2=/usr/local/apache/bin/apxs

make

cd ../build/jk2/apache2/

/usr/local/apache/bin/apxs -n jk2 -i mod_jk2.so

(2).查看Apache模块

mod_jk2.so

(3).编辑Apache配置文件

vim /usr/local/apache/conf/httpd.conf

LoadModule jk2_module modules/mod_jk2.so

(4).编辑虚拟主机

NameVirtualHost *:80

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/data/html"

    ServerName www.free.com

    ErrorLog "logs/www.free.com.error.log"

    CustomLog "logs/www.free.com.access.log" combined

    <Directory "/data/html">

        Options Indexes FollowSymLinks

        DirectoryIndex index.html index.jsp index.htm

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>

</VirtualHost>

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/data/html/wordpress"

    ServerName blog.free.com

    ErrorLog "logs/blog.free.com.error.log"

    CustomLog "logs/blog.free.com.access.log" combined

    <Directory "/data/html/wordpress">

        Options Indexes FollowSymLinks

        DirectoryIndex index.html index.jsp index.htm

        AllowOverride None

        Order allow,deny

        Allow from all

    </Directory>

</VirtualHost>

(5).增加Tomcat的配置文件

cd /usr/local/apache/conf/

vim workers2.properties

[logger.apache]

level=DEBUG

[shm]

file=/usr/local/apache/logs/shm.file

size=1048576

#Example socket channel override port and host.

[channel.socket:localhost:8009]

port=8009

host=127.0.0.1

#define the worker

[ajp13:localhost:8009]

channel=channel.socket:localhost:8009

#Uri mapping

[uri:/*.jsp]

[uri:/servlet/*]

[uri:/*.vm]

[uri:/*.do]

worker=ajp13:localhost:8009

(6).Tomcat配置虚拟主机

<Host name="www.free.com" debug="0" appBase="/data/html">

    <Context path="/" docBase="/data/html" debug="0"/>

</Host>

(7).测试

cd /data/html

vim index.jsp

<html>

        <body>

                <center>

                        Now time is :<%=new java.util.Date()%>

                </center>

        </body>

</html>

/usr/local/apache/bin/apachectl -t

/usr/local/apache/bin/apachectl -S

/usr/local/apache/bin/apachectl start

/usr/local/tomcat/bin/catalina.sh start



IE:

注意: 指定HOSTS


http://www.free.com


效果如下:


Now time is :Tue Feb 26 12:47:51 CST 2013


本文出自 “眼眸刻着你的微笑” 博客,请务必保留此出处http://dengaosky.blog.51cto.com/9215128/1855315

以上是关于Apache整合Tomcat的主要内容,如果未能解决你的问题,请参考以下文章

记一次java环境下安装php的过程

升级tomcat需要更改哪些配置?

CentOS 7安装tomcat 7

apache整合tomcat部署集群

django专题—整合apache整合nginx

Apache+Tomcat整合