Why should integrate Apache with Tomcat

There are many reasons to integrate Tomcat with Apache. And there are reasons why it should not be done too. Needless to say, everyone will disagree with the opinions here. With the performance of Tomcat 5 and 6, performance reasons become harder to justify. So here are the issues to discuss in integrating vs not.

  • Clustering. By using Apache as a front end you can let Apache act as a front door to your content to multiple Tomcat instances. If one of your Tomcats fails, Apache ignores it and your Sysadmin can sleep through the night. This point could be ignored if you use a hardware loadbalancer and Tomcat's clustering capabilities.

  • Clustering/Security. You can also use Apache as a front door to different Tomcats for different URL namespaces (/app1/, /app2/, /app3/, or virtual hosts). The Tomcats can then be each in a protected area and from a security point of view, you only need to worry about the Apache server. Essentially, Apache becomes a smart proxy server.

  • Security. This topic can sway one either way. Java has the security manager while Apache has a larger mindshare and more tricks with respect to security. I won't go into this in more detail, but let Google be your friend. Depending on your scenario, one might be better than the other. But also keep in mind, if you run Apache with Tomcat - you have two systems to defend, not one.

  • Add-ons. Adding on CGI, perl, PHP is very natural to Apache. Its slower and more of a kludge for Tomcat. Apache also has hundreds of modules that can be plugged in at will. Tomcat can have this ability, but the code hasn't been written yet.

  • Decorators! With Apache in front of Tomcat, you can perform any number of decorators that Tomcat doesn't support or doesn't have the immediate code support. For example, mod_headers, mod_rewrite, and mod_alias could be written for Tomcat, but why reinvent the wheel when Apache has done it so well?

  • Speed. Apache is faster at serving static content than Tomcat. But unless you have a high traffic site, this point is useless. But in some scenarios, tomcat can be faster than Apache httpd. So benchmark YOUR site. Tomcat can perform at httpd speeds when using the proper connector (APR with sendFile enabled). Speed should not be considered a factor when choosing between Apache httpd and Tomcat

  • Socket handling/system stability. Apache has better socket handling with respect to error conditions than Tomcat. The main reason is Tomcat must perform all its socket handling via the JVM which needs to be cross platform. The problem is socket optimization is a platform specific ordeal. Most of the time the java code is fine, but when you are also bombarded with dropped connections, invalid packets, invalid requests from invalid IP's, Apache does a better job at dropping these error conditions than JVM based program.

 

有很多的理由将Tomcat和Apache集成,同样也有很多的理由不这样做。在Tomcat 5中,性能不在是决定性因素。以下就是集成与不集成的讨论:

1、聚合。使用Apache做为前端大门,后端部署多个Tomcat实例,如果一个实例出现问题,Apache将忽略这个实例,让系统管理员高枕无忧。当然如果在硬件负载均衡设备的基础上利用Tomcat的聚合能力就没有必要进行集成了。

2、聚合/安全。当然如果使用Apache做为门户来区分拥有不同URL命名空间的不同的Tomcat。每个Tomcat都成为一个保护区域,从安全角度讲,仅仅需要主要Apache 服务器。在这个方案中,Apache已经变成一个轻量级的代理服务器。

3、安全。就安全来讲,集成和不集成都是争论双方的焦点。Java有安全管理功能,Apache对安全考虑的也是比较周道的。可以使用Google来查阅 这方面的资料。在某个场合中,集成是上上策,但是另外一个场合,可能不集成略胜一筹。但是如果集成Apache和Tomcat,一定要记住:你需要同时关 注Apache和Tomcat的安全,而不是一个。

4、附加因素。在Apache上运行perl,PHP和CGI都是很普通的事情。但是对Tomcat来说,不仅速度忙,而且不太正式。Apache可以任意添加上百个附加软件,当然Tomcat也有这个能力,但是这样的模块还没有开发出来。

5、装饰。当Apache做为Tomcat前端时,你可以完成大量Tomcat不支持或没有现成代码的装饰工作。没有必要重新为Tomcat开发一套类似为Apache的mod_headers,mod_rewrite, and mod_alias。

6、速度。Apache的静态网页处理速度高于Tomcat。但是除非你的流量很大,这一点时没有意义的。在另外一些情况下,Tomcat要比Apache快。所以两者结合可以加速你的站点。

7、Socket handling(姑且认为是连接)/系统稳定性。Apache在处理错误链接上优于Tomcat。主要原因是Tomcat所有的连接都交给JVM来处 理,而JVM是跨平台的,问题是跨平台的优化是一个严峻的考验。大部分时间java程序都是正常的,但是当情况非常恶劣时,例如:非常频繁的掉线,无效数 据包,无效IP的无效请求。Apache比基于JVM的程序要好。

 



原文http://tomcat.apache.org/faq/connectors.html#integrate

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值