网站运营
位置:首页>> 网站运营>> RedHat7.2下Apache与Tomcat4整合实例(2)

RedHat7.2下Apache与Tomcat4整合实例(2)

 来源:asp之家 发布时间:2010-05-16 18:10:00 

标签:apache,redhat,tomcat

三、虚拟主机下的配置、管理和应用

   下面以一个例子来说明虚拟主机如何同时使用Apache与Tomcat4

   虚拟主机host1的目录结构如下所示:


   /www               
    |---host1  虚拟主机host1的主目录
    |  |--htdocs  普通根目录:用于显示静态页面或php程序
    |  |----logs  apache访问日志
    |  |----webapps java应用目录(新加,与tomcat的webapps目录无任何关联)
    |     |--ROOT jsp根目录:用于显示jsp页面程序
    |     |----jive 一套java应用实例
    |---host2   虚拟主机host2的主目录
   ............



   原来的apache的配置文件是这样配置的:


   =====================================
   NameVirtualHost xxx.xxx.xxx.xxx

   < VirtualHost xxx.xxx.xxx.xxx >
   ServerName host1.mydomain.com
   ServerAdmin webmaster@mydomain.com
   DocumentRoot /www/host1/htdocs
   ErrorLog /www/host1/logs/error_log
   CustomLog /www/host1/logs/access_log common
   < /VirtualHost >
   .............

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



   现在要让虚拟主机host1能同时使用Apache与Tomcat4,需要做如下配置:

   1、编辑tomcat的配置文件server.xml,在最后的部分做如下修改:


   =====================================
   < !-- Define an Apache-Connector Service -- >

   < Service name="Tomcat-Apache" >

   < Connector className="org.apache.catalina.connector.warp.WarpConnector"
   port="8008" minProcessors="5" maxProcessors="75"
   enableLookups="true" appBase="webapps"
   acceptCount="10" debug="0"/ >

< Engine className="org.apache.catalina.connector.warp.WarpEngine"
   name="Apache" debug="0" >

   < Logger className="org.apache.catalina.logger.FileLogger"
   prefix="apache_log." suffix=".txt"
timestamp="true"/ >

   < Realm className="org.apache.catalina.realm.MemoryRealm" / >

< !-- 下面是新加的内容 -- >

   < Host name="host1.mydomain.com" debug="0" appBase="/www/host1/webapps"
uppackWars="true" autoDeploy="true" >
   < Context path="" docBase="ROOT" debug="0"/ >
< !-- 下面套用的是tomcat自带的管理页面,在虚拟主机下也可使用 -- >
< Context path="/manager" debug="0" privileged="true"
   docBase="/opt/tomcat/server/webapps/manager"/ >
   < Context path="/jive" docBase="jive" debug="0"
reloadable="true" crossContext="true"/ >
   < Logger className="org.apache.catalina.logger.FileLogger"
prefix="host1_log." suffix=".txt"
   timestamp="true"/ >
   < /Host >

< !-- 新加内容结束 -- >

< /Engine >

   < /Service >
   =====================================



   2、编辑tomcat的管理权限文件tomcat-users.xml,在中间加一行:


< user username="myname" password="mypasswd" roles="standard,manager"/ >



   3、编辑apache的配置文件,做如下修改:


   =====================================
   LoadModule webapp_module libexec/mod_webapp.so
   AddModule mod_webapp.c
   WebAppConnection warpConnection warp localhost:8008

   NameVirtualHost xxx.xxx.xxx.xxx

   < VirtualHost xxx.xxx.xxx.xxx >
   ServerName host1.mydomain.com
   ServerAdmin webmaster@mydomain.com
   DocumentRoot /www/host1/htdocs
   ErrorLog /www/host1/logs/error_log
   CustomLog /www/host1/logs/access_log common

   WebAppDeploy ROOT warpConnection /

   #注:此行的作用是把ROOT目录作为虚拟主机URL的根,并使前面定义的根htdocs失效。
   #但如果不想整个虚拟主机都使用jsp页面程序,而想使用大量静态页面或php程序的话,
   #就要使用下面这行,并把所有的静态页面和php程序放在htdocs目录下。
   # WebAppDeploy ROOT warpConnection /jsp

   WebAppDeploy manager warpConnection /manager
   WebAppDeploy jive warpConnection /jive
   #在server.xml里每定义一个都要在这里加一条WebAppDeploy。

   < /VirtualHost >

   .............
   =====================================

   4、将tomcat用户设成/www/host1/webapps以下所有目录文件的属主。

   要注意的是,以后如果想上传或改动该目录以下的文件,都要将其属主改成tomcat。

   (如果一直是以root身份运行tomcat,这步可以省略。)
   # chown -R tomcat:tomcat /www/host1/webapps
   5、重起tomcat:
   # su - tomcat -c "/opt/tomcat/bin/shutdown.sh"
   # su - tomcat -c "/opt/tomcat/bin/startup.sh"
   6、重起apache:
   /usr/local/apache/bin/apachectl restart
   此时访问http://host1.mydomain.com/manager/html 会提示输入密码,在输入正确的 myname和mypasswd后,就会看到“Tomcat Web Application Manager”的页面,里面的 Application Path已经是虚拟主机里配置的信息了,并可以对其进行管理。

   到此虚拟主机下的配置和管理就全部完成,剩下的事情就是测试和应用了。在上面的例子

   里我们已经安装了jive,经测试已经可以正常运行。

0
投稿

猜你喜欢

手机版 网站运营 asp之家 www.aspxhome.com