Tomcat6.0与Apache的整合(http-proxy方式)


1、第一:要求

1)Tomcat与apache的整合,如果采用http-proxy连接方式,那么apache必须使用的版本是:2.2.X

2)apache必须加载两个模块:mod_proxy.so、mod_proxy_http.so

注意:apache默认已经加载了mod_proxy.so,所以还需要 mod_proxy_http.so,确认是否已经含有这两个模块,运行指令:ls -l /lamp/web/apache/modules/mod_proxy*,如果找不到mod_proxy_http.so模块,那么必须手动编译,具体的方法如下:
(1)下载apache的源码包:
wget http://archive.apache.org/dist/httpd/httpd-2.2.15.tar.gz
(2)解压apache的源码包,然后到目录httpd-2.2.15/modules/proxy目录,找到mod_proxy_http.c
(3)使用apxs来生成mod_proxy_http.so:/lamp/apache/bin/apxs -c -i mod_proxy_http.c
(4)最后再确认一下
/lamp/web/apache/modules目录已经有该模块文件:mod_proxy_http.so

================================================================

2、第二步:相关配置

1)配置apache的配置文件,加载两个模块
root@Mylinux ~]# vi /lamp/web/apache/etc/
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

#配置主页默认文件#
[root@Mylinux ~]# vi /lamp/web/apache/etc/httpd.conf
DirectoryIndex index.jsp index.php index.htm index.html.var

--------------------------------------------------------------------------------------------------------------

2)配置tomcat的server.xml文件
root@Mylinux ~]# vi /lamp/web/tomcat/conf/server.xml
(1)由于采用了是ajp-proxy方式连接,所以tomcat需要监听http协议的8080端口
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
(2)出于安全考虑注释掉默认的tomcat首页,所以注释掉下面几行
<!--
<Host name="localhost" appBase="" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" />
-->

(3)添加虚拟主机
<Host name="www.sogua.com" appBase="" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/jsp1" docBase="/lamp/mysite/jsp1" reloadable="true" crossContext="true"/>
</Host>
<Host name="www.sokua.com" appBase="" unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/jsp2" docBase="/lamp/mysite/jsp2" reloadable="true" crossContext="true"/>
</Host>

--------------------------------------------------------------------------------------------------------------

3)配置Apache的虚拟目录及虚拟主机
(1)配置虚拟目录
Alias "/jsp1" "/lamp/web/mysite/web-jsp1"
Alias "/jsp2" "/lamp/web/mysite/web-jsp2"
Alias "/php" "/lamp/web/mysite/web-php"
Alias "/html" "/lamp/web/mysite/web-html"
<Directory "/lamp/web/mysite/web-jsp1">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<Directory "/lamp/web/mysite/web-jsp2">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<Directory "/lamp/web/mysite/web-php">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<Directory "/lamp/web/mysite/web-html">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>


(2)配置虚拟主机
[root@Mylinux ~]# vi /lamp/web/apache/etc/httpd.conf
Include etc/extra/httpd-vhosts.conf
[root@Mylinux ~]# vi /lamp/web/apache/etc/extra/httpd-vhosts.conf
NameVirtualHost 192.168.0.100:80
<VirtualHost www.sogua.com>
ServerName sogua
ServerAdmin [email protected]
DocumentRoot /lamp/web/mysite/web-jsp1
DirectoryIndex index.jsp
ErrorLog logs/web-jsp1/error_log
CustomLog logs/web-jsp1/access_log combined
ProxyPass /images !
ProxyPass /php !
ProxyPass /css !
ProxyPass /js !
#ProxyPass / http://tomcat的虚拟主机名(server.xml文件中所定义的虚拟主机名):8080/
ProxyPass / http://www.sogua.com:8080/
#ProxyPassReverse / http://tomcat的虚拟主机名(server.xml文件中所定义的虚拟主机名):8080/
ProxyPassReverse / http://www.sogua.com:8080/
</VirtualHost>

<VirtualHost www.sokua.com>
ServerName sokua
ServerAdmin [email protected]
DocumentRoot /lamp/web/mysite/web-jsp2
DirectoryIndex index.jsp
ErrorLog logs/web-jsp2/error_log
CustomLog logs/web-jsp2/access_log combined
ProxyPass /images !
ProxyPass /php !
ProxyPass /css !
ProxyPass /js !
ProxyPass / http://www.sokua.com:8080/
ProxyPassReverse / http://www.sokua.com:8080/

</VirtualHost>

<VirtualHost www.sogua.com>
ServerName sogua
ServerAdmin [email protected]
DocumentRoot /lamp/web/mysite/web-php
DirectoryIndex index.php
ErrorLog logs/web-php/error_log
CustomLog logs/web-php/access_log combined
</VirtualHost>

<VirtualHost www.sogua.com>
ServerName sogua
ServerAdmin [email protected]
DocumentRoot /lamp/web/mysite/web-html
DirectoryIndex index.html
ErrorLog logs/web-html/error_log
CustomLog logs/web-html/access_log combined
</VirtualHost>


你可能感兴趣的:(apache,html,tomcat,jsp,Module,Path)