apache2.2 integrates tomcat6.0 using proxy_ajp method

WBOY
Release: 2016-08-08 09:29:56
Original
1367 people have browsed it

Apache2.2 uses proxy ajp way to integrate Tomcat6.0

小wolf@http://blog.csdn.net/xiaolangyangyang

There are quite a few articles like this on Google. But some of them are not complete and not suitable for me. I had to write it myself

This article mainly uses httpd2.2's porny_ajp to connect to tomcat

My environment is: Centos5.2

Download the latest version of apache. The latest version is httpd-2.2.10.tar.gz

Download the latest version of tomcat. The latest version is apache-tomcat-6.0.18.tar.gz

jdk1.6

at http://apr.apache.org Download the latest apr-1.3.3 and apr-util-1.3.4

1. Start the installation

1. #Compile apr

#tar -zxvf apr-1.3.3.tar.gz

#cd apr -1. 3.3

#./configure--prefix=/ usr/local/ apr-httpd/

#make

#make install

2. #compile apr-util

#tar -zxvf apr-util-1.3.4.tar.gz#cd apr-util-1.3.4#./configure--prefix=/usr/local/apr-util-httpd/--with-apr=/usr/local/apr -httpd/ #make#make install

3. #compile httpd

#tar-zxvf httpd-2.2.10.tar.gz#cd httpd-2.2.10#./configure--prefix=/usr/local/apache2/--with-apr=/usr/local/apr-httpd/--with-apr-util=/usr/local/apr-util-httpd/--enable-so--enable-mods-shared=most--enable-rewrite=shared--enable-proxy=shared--enable -proxy-ajp =shared--enable-proxy-balancer=shared- -enable-speling =shared#make#make install

Start:

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

Test whether the installation is correct. Use this http://yourip/ to display the apache default page. It works!

4. Configure tomcat

1) #Install JDK1.6

Download jdk from java.sun.com and install it directly

2) #Set environment variables

vim /etc/profile Add:

export JAVA_HOME=/usr/java/jdk
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Copy after login

3 ) #Install tomcat

#tar-zxvf apache-tomcat-6.0.18.tar.gz -C/usr /local/#mv/usr/local/apache-tomcat -6. 0.18 tomcat

4) Start tomcat and test

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

5) 访问:http://yourip:8080/如果看到默认首页证明安装成功

二.整合apache和tomcat

我这里的apache的根目录和tomcat的根目录不在同一目录,当然了你完全可以放在同一目录下

我的apache的根目录在/www tomcat的根目录在/usr/local/tomcat/webapps

修改apache的httpd.conf

添加模块:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
Copy after login

打开Virtual hosts 即去掉Include conf/extra/httpd-vhosts.conf一行的注释

注释掉DocumentRoot和ServerAdmin

编辑httpd-vhosts.conf

添加:

<VirtualHost*:80>
    ServerAdmin jsjzhang@gmail.com
    DocumentRoot "/www/web"         #此虚拟主机的主目录为/www/web
   <Directory "/www/web">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    ServerName www.terr.com         #只是测试,生产环境可以写为对应的域名
    ProxyPass /images !             #以下几行的意思是对/images,/sna  和/news/images几个目录的访问请求由apache处理其它都由tomcat处理.
    ProxyPass /sna !
    ProxyPass /news/images!
    ProxyPass / ajp://localhost:8009/

    ProxyPassReverse / ajp://localhost:8009/

    ErrorLog "logs/3.249-error_log"
    CustomLog "logs/3.249-access_log" common
</VirtualHost>
Copy after login
如何有多个虚拟主机可以再添加.例如:
<VirtualHost*:80>
    ServerAdmin jsjzhang@gmail.com
    DocumentRoot "/www/web2" 
   <Directory "/www/web2">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

    ServerName www.terr2.com            
    ProxyPass /images !             
    ProxyPass /sna !
    ProxyPass /news/images!
    ProxyPass / ajp://localhost:8009/

    ProxyPassReverse / ajp://localhost:8009/

    ErrorLog "logs/3.249-error_log"
    CustomLog "logs/3.249-access_log" common
</VirtualHost>
Copy after login

注: 生产环境下这些虚拟主机都是用域名访问的.因为他们都对应同一个IP。如何用IP访问一般打开的为最一个虚拟主机的主页。

把web这个网站放到tomcat的主目录/usr/local/tomcat/webapps下,其中images,sna和/news/images这三个目录放到/www/web下当然了我的apache还有其它用处所以没有和tomcat设为同一主目录为了简单你当然可以这么做,但一定要记得把apache中虚拟主机中的修改为和你tomcat一致的主目录,例如我这里应

该设为:

三.测试

现在启动tomcat启动apache在浏览器输入http://www.terr.com/web看看效果吧,因为是测试所以我在只在hosts里面对www.terr.com做了解析。

以上就介绍了apache2.2用proxy_ajp方式整合tomcat6.0,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template