apache中有virtual host如何配置mod_jk

目标:针对apache中已配置了多个virtual host的情况,将如何进行mod_jk的配置,以解决动静分离处理的目的。

步骤:

1)假定Apache与Tomcat 已经安装,对应的端口分别是8088和8080

   其中:apache的安装路径是/home/work/local/apache/

2)安装Mod_JK

cd /home/work/jn

tar xzvftomcat-connectors-1.2.30-src.tar.gz

cd tomcat-connectors-1.2.30-src

cd native/

//将jk安装为apache的一个模块

./configure --with-apxs=/home/work/local/apache/bin/apxs

make

make install

 3)置apache监听端口和 mod_jk

//修改httpd.conf,

vi /home/work/local/apache/conf/httpd.conf

添加如下内容

LoadModule    jk_module modules/mod_jk.so

Include /home/work/local/apache/conf/mod_jk.conf

JkMountCopy All

//在httpd.conf中配置了虚拟主机,那么应该在每一个 VirtualHost 部分加入,否则会在mod_jk.log 中发现mod_jk.c (3033): missing uri map

JkMountCopy On

//如果拥有很多虚拟主机配置段,也可以使用在配置文件的开头部分中写入,表示对全部虚拟主机进行配置

JkMountCopy All

4)apache/conf添加mod_jk配置文件

在apache/conf下添加文件mod_jk.conf内容为:

 <IfModule mod_jk.c>
 JkWorkersFile conf/workers.properties
 JkLogFile  logs/mod_jk.log
 JkLogLevel debug
 # Sample JkMounts.  Replace these with the paths you would
 # like to mount from your JSP server.
 JkMount /*.jsp ajp13w
 JkMount /servlet/* ajp13w
 JkMount /examples/* ajp13w

# Following are JkMounts for your application
 JkMount /preference/** ajp13w
 JkMount /api** ajp13w
 JkMount /uajax/get ajp13w
 JkMount /system_const/** ajp13w
#也可指定静态文件
JkMount /main.html** ajp13w  
JkMount /main.html#/* ajp13w
</IfModule>

在apache/conf下 添加文件 workers.properties,内容为:

worker.list=ajp13w,wlb,jkstatus
worker.ajp13w.type=ajp13
worker.ajp13w.host=localhost
worker.ajp13w.port=8009
worker.wlb.type=lb
worker.wlb.balance_workers=ajp13w
worker.jkstatus.type=status



重新启动apache
cd /home/work/local/apache/bin
./apachectl stop
./apachectl restart

5)设置tomcat的启动参数

vi /home/work/local/apache-tomcat-5.5.31/bin/catalina.sh

在# OS specific support这个section会给tomcat分配内存,最大4G,PerSize 最大256m

#如应用程序设置

JAVA_OPTS="-server -Xms1024m-Xmx4096m -Xmn512m -XX:PermSize=96m -XX:MaxPermSize=256m"

6)设置tomcat主目录

vi /home/work/local/apache-tomcat-5.5.31/conf/server.xml

在tomcat的conf/server.xml  文件最末在<host>与</host>之间加上如下代码,配置新的Webapp应用

//将tomcat的docBase指向apache某一个虚拟主机目录

<ContextdocBase="/home/work/local/apache/htdocs/site18/" path="">

</Context>

重启tomcat,使以上修改生效

./home/work/local/apache-tomcat-5.5.31/bin/shutdown.sh

./home/work/local/apache-tomcat-5.5.31/bin/startup.sh

7)编辑简单的.jsp测试文件。  
# vi /home/apache/-1.3.19/htdocs/test.jsp  
<html>  
<head>  
<title> This is a jsp test file!  
</title>  
</head>  
<body>  
<% out.print("This is a jsp test file!"); %>  
</body>  
</html>

分别测试以下两个网址

http://tc-web00.tc.com:8080/test.jsp  //8080能够显示说明tomcat正常工作

http://tc-web00.tc.com:8088/test.jsp  //8088能够显示说明apache可以处理jsp文件了,也就是说apache tomcat之间能够互相连通


你可能感兴趣的:(apache中有virtual host如何配置mod_jk)