linux下利用mod-jk2实现apache和tomcat整合
Thursday, 11. January 2007, 07:09:42
说明:mod-jk2是一个tomcat和web服务器的连接器,但是它并没有比它开始的早的mod-jk好用,因此整合tomcat和apache还是推荐mod-jk,更详细的信息可以在http://tomcat.apache.org/connectors-doc/找到,mod-jk2目前已经是deprecated了,如下面的说明:
In order to make the connection between Tomcat and Apache, we will need to download and install mod_jk connector. You will find that the Apache documentation recommends that you install the packaged version of mod_jk if it is available for your particular Linux distribution. Many outdated resources recommend installing the mod_jk2 connector, but I have found that it has been deprecated and although mod_jk was developed before mod_jk2, it is still fully supported and is very stable.
下面就以ubuntu下得用mod-jk2实现apache和tomcat整合进行说明,注意,新版本的ubuntu(如6.10)源中已经没有了mod-jk2,只有mod-jk,因此,下面的内容只适用于老版本作参考。
1.安装apache
sudo apt-get install apache2
编辑/etc/apache2/apache2.conf文件,在改动之前,请先将该配置文件做个备份。以便在出错的时候可以恢复。
AddDefaultCharset ISO-8859-1 =>AddDefaultCharset GB2312
这样的话,我们就不会每次打开网页都是乱码了!
2.安装mod-jk2模块
sudo apt-get install libapache2-mod-jk2
这是完整的包名。
3.配置
首先,在tomcat目录的conf文件夹下创建jk2.properties文件,在里面加入
handler.list=channelSocket,request
channelSocket.port=8009
两行。然后将/usr/share/doc/libapache2-mod- jk2/examples/workers2.properties.minimal复制到/etc/apache2/目录下,并改名为 workers2.properties,编辑这个文件,将其中
[config:]
file=${serverRoot}/conf/workers2.properties
debug=0
debugEnv=0
这段改为:
[config:]
file=${serverRoot}/workers2.properties
debug=0
debugEnv=0
保存修改,最后编辑/etc/apache2/mods-available/jk2.conf文件,去掉最后一行:
#JkSet config.file /etc/apache2/workers2.properties
的注释。
保存并退出编辑,OK,至此apache和tomcat的整合工作已经完成。当然,我今天写的只是最基本的让apache和tomcat协同工作的方法,有很多设置需要你根据的需求自己进行修改。
还有,在另外建了站点以后(如果没有在/tomcat/path/webapps目录下),还要在 workers2.propertier定义uri路径,也就是客户端的请求从apache转到tomcat中的哪些类型文件可以被转发.有一个万用的方法就是定义如下的URI:
[uri:/*]
debug=0
也就是所有的文件类型都可以由apache转到tomcat中进行编译.
当然,这就是对服务器的性能有所折扣了。
4.重启服务器
重启tomcat和apache
基中要使用/etc/init.d/apache2 -k (start|stop) 等命令来启动或关闭apache
In order to make the connection between Tomcat and Apache, we will need to download and install mod_jk connector. You will find that the Apache documentation recommends that you install the packaged version of mod_jk if it is available for your particular Linux distribution. Many outdated resources recommend installing the mod_jk2 connector, but I have found that it has been deprecated and although mod_jk was developed before mod_jk2, it is still fully supported and is very stable.
下面就以ubuntu下得用mod-jk2实现apache和tomcat整合进行说明,注意,新版本的ubuntu(如6.10)源中已经没有了mod-jk2,只有mod-jk,因此,下面的内容只适用于老版本作参考。
1.安装apache
sudo apt-get install apache2
编辑/etc/apache2/apache2.conf文件,在改动之前,请先将该配置文件做个备份。以便在出错的时候可以恢复。
AddDefaultCharset ISO-8859-1 =>AddDefaultCharset GB2312
这样的话,我们就不会每次打开网页都是乱码了!
2.安装mod-jk2模块
sudo apt-get install libapache2-mod-jk2
这是完整的包名。
3.配置
首先,在tomcat目录的conf文件夹下创建jk2.properties文件,在里面加入
handler.list=channelSocket,request
channelSocket.port=8009
两行。然后将/usr/share/doc/libapache2-mod- jk2/examples/workers2.properties.minimal复制到/etc/apache2/目录下,并改名为 workers2.properties,编辑这个文件,将其中
[config:]
file=${serverRoot}/conf/workers2.properties
debug=0
debugEnv=0
这段改为:
[config:]
file=${serverRoot}/workers2.properties
debug=0
debugEnv=0
保存修改,最后编辑/etc/apache2/mods-available/jk2.conf文件,去掉最后一行:
#JkSet config.file /etc/apache2/workers2.properties
的注释。
保存并退出编辑,OK,至此apache和tomcat的整合工作已经完成。当然,我今天写的只是最基本的让apache和tomcat协同工作的方法,有很多设置需要你根据的需求自己进行修改。
还有,在另外建了站点以后(如果没有在/tomcat/path/webapps目录下),还要在 workers2.propertier定义uri路径,也就是客户端的请求从apache转到tomcat中的哪些类型文件可以被转发.有一个万用的方法就是定义如下的URI:
[uri:/*]
debug=0
也就是所有的文件类型都可以由apache转到tomcat中进行编译.
当然,这就是对服务器的性能有所折扣了。
4.重启服务器
重启tomcat和apache
基中要使用/etc/init.d/apache2 -k (start|stop) 等命令来启动或关闭apache







How to use Quote function: