Linux下整合Apache和Tomcat

时间:2022-06-15 19:11:19


Tomcat是一个JSP容器,Apache是一个Web Server,通常将Tomcat与Apache绑定在一起,由Tomcat处理用户的动态内容请求,由Apache处理用户的静态内容请求. 


1.安装Tomcat6
[1]在[url]http://tomcat.apache.org/download-60.cgi[/url]下载Binary Distributions Core版本的tar.gz.
[2]解压之后即可使用.在Linux下,启动和停止Tomcat分别使用脚本
%TOMCAT_HOME%/bin/startup.sh
%TOMCAT_HOME%/bin/shutdown.sh
[3]验证安装
[3.1]执行startup.sh
[3.2]在浏览器下输入[url]http://localhost:8080/[/url]后出现
Linux下整合Apache和Tomcat
说明安装成功.

2.配置Apache2(RedHat下缺省安装)
[1]可在Apache官方网站下载并编译安装Apache.
[2]启动
[root@localhost ~]# /etc/init.d/httpd start
[3]验证安装
[3.1]新建hello.html,放置在/var/www/html下
< html >    
< head > < title >Hello </title> </head>   
< body >

< p >Hello
</body>    
</html>
[3.2]在浏览器下输入
[url]http://localhost/hello.html/[/url]后出现Hello说明安装成功.

3.将Tomcat绑定到Apache
[1]下载tomcat-connectors
在[url]http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/[/url]下根据自己Apache版本和硬件环境选择适当的版本,将该链接文件改名为mod_jk.so将其放在/etc/httpd/modules目录下.
[2]修改/etc/httpd/conf目录下httpd.conf,在文件末尾加入
#for tomcat
include "/usr/local/apache2/conf/mod_jk.conf"
[3]新建/usr/local/apache2/conf/mod_jk.conf,内容为
#Load mod_jk module
LoadModule jk_module modules/mod_jk.so
#Where to find workers.properties
JkWorkersFile conf/workers.properties
#Where to put jk logs
JklogFile logs/mod_jk.log
#Set the jk log level[debug/error/info]
JkLogLevel info
#Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
#JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
#JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
#Send servlet for context /examples to worker named ajp13
#JkMount /servlet/* ajp13
#Send JSPs for context /examples to worker named ajp13
JkMount /*.jsp ajp13
[4]配置worker
在/etc/httpd/conf/下新建workers.properties文件,其内容为
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
[5]重起Apache
/etc/init.d/httpd restart
如果出现:
启动 httpd:Syntax error on line 2 of /usr/local/apache2/conf/mod_jk.conf:
Cannot load /etc/httpd/modules/mod_jk.so into server: /etc/httpd/modules/mod_jk.so: invalid ELF header
则说明mod_jk.so的版本错误.
[6]验证安装
[6.1]在%TOMCAT_HOME%/webapps/ROOT下新建一个JSP文件hello.jsp,其内容为
< html >    
< head > < title >Hello </title> </head>   
< body >
<%
java.util.Date currentTime = new java.util.Date();
%>
< %=currentTime% >
</body>    
</html>
[6.2]在浏览器下输入
[url]http://localhost/hello.jsp[/url]

即可得到当前系统时间,说明安装成功.

http://zhangjunhd.blog.51cto.com/113473/80636/