Apache HTTP Server vs Apache Tomcat
来源: 知乎:tomcat 与 nginx,apache的区别是什么?
严格的来说,Apache/Nginx 应该叫做「HTTP Server」;而 Tomcat 则是一个「Application Server」,或者更准确的来说,是一个「Servlet/JSP」应用的容器(Ruby/Python 等其他语言开发的应用也无法直接运行在 Tomcat 上)。
题主说的Apache,指的应该是Apache软件基金会下的一个项目—— Apache HTTP Server Project
;Nginx同样也是一款开源的HTTP服务器软件(当然它也可以作为邮件代理服务器、通用的TCP代理服务器)。
HTTP服务器本质上也是一种应用程序——它通常运行在服务器之上,绑定服务器的IP地址并监听某一个tcp端口来接收并处理HTTP请求,这样客户端(一般来说是IE, Firefox,Chrome这样的浏览器)就能够通过HTTP协议来获取服务器上的网页(HTML格式)、文档(PDF格式)、音频(MP4格式)、视频(MOV格式)等等资源。下图描述的就是这一过程:
不仅仅是Apache HTTP Server和Nginx,绝大多数编程语言所包含的类库中也都实现了简单的HTTP服务器方便开发者使用:
使用这些类库能够非常容易的运行一个HTTP服务器,它们都能够通过绑定IP地址并监听tcp端口来提供HTTP服务。
Apache Tomcat则是Apache基金会下的另外一个项目,与Apache HTTP Server相比,Tomcat能够
动态的生成资源并返回到客户端。Apache HTTP Server和Nginx都能够将某一个文本文件的内容通过HTTP协议返回到客户端,但是这个文本文件的内容是固定的——也就是说无论何时、任何人访问它得到的内容都是完全相同的,这样的资源我们称之为
静态资源。动态资源则与之相反,在不同的时间、不同的客户端访问得到的内容是不同的,例如:
Apache HTTP Server和Nginx本身不支持生成动态页面,但它们可以通过其他模块来支持(例如通过Shell、PHP、Python脚本程序来动态生成内容)。
如果想要使用Java程序来动态生成资源内容,使用这一类HTTP服务器很难做到。 Java Servlet技术以及衍生的 Java Server Pages技术可以让Java程序也具有处理HTTP请求并且返回内容(由程序动态控制)的能力,Tomcat正是支持运行Servlet/JSP应用程序的容器(Container):
Tomcat运行在JVM之上,它和HTTP服务器一样,绑定IP地址并监听TCP端口,同时还包含以下指责:
虽然Tomcat也可以认为是HTTP服务器,但通常它仍然会和Nginx配合在一起使用:
-
动静态资源分离——运用Nginx的反向代理功能分发请求:所有动态资源的请求交给Tomcat,而静态资源的请求(例如图片、视频、CSS、JavaScript文件等)则直接由Nginx返回到浏览器,这样能大大减轻Tomcat的压力。
-
负载均衡,当业务压力增大时,可能一个Tomcat的实例不足以处理,那么这时可以启动多个Tomcat实例进行水平扩展,而Nginx的负载均衡功能可以把请求通过算法分发到各个不同的实例进行处理
-----------------------------------------------------------
Apache Tomcat is used to deploy your Java Servlets and JSPs. So in your Java project you can build your WAR (short for Web ARchive) file, and just drop it in the deploy directory in Tomcat.
So basically Apache is an HTTP Server, serving HTTP. Tomcat is a Servlet and JSP Server serving Java technologies.
Tomcat is a servlet container. A servlet, at the end, is a Java class. JSP files (which are similar to PHP, and older ASP files) are generated into Java code (HttpServlet), which is then compiled to .class files by the server and executed by the Java virtual machine.
Apache HTTP server is often used with Tomcat, where static content is handled by the Apache Http server and Tomcat handles the dynamic content.
In addition to the fine answers above, I think it should be said that Tomcat has it's own HTTP server built into it, and is fully functional at serving static content too. Depending on your java virtual machine configuration it can actually outperform going through traditional connectors in apache such as mod_proxy and mod_jk.
That said a fully optimized Tomcat server should serve static files fast and if you have Java servlets, JSPs and ColdFusion files in addition to static content you may find tomcat does an excellent job by itself.
Apache vs Nginx
有着诸多优势的Nginx如今已是增长最快的Web服务器了,截止今年4月,7年前仅有3.9%占有率的Nginx已经增长到如今的33.3%,这代表着平均每分钟就有一个排名前1000万以内的网站改弦更张,将老服务器替换成Nginx。而相对同样快速增长的Web服务器Node.js,改用Nginx的网站达到了改用Node.js网站数量的70倍。
此外,自2010年以来,Apache的市场份额从71.5%下滑至50%不到,而微软的IIS则从20.6%下滑到11.3%。结果不出所料,大多原本使用Apache的网站都改用了Nginx。大部分流量较大的网站都很喜欢使用Nginx,在流量最大的前1万个网站中,有58.4%使用Nginx。不过,在流量最大的前100万个网站中,Apache的市场份额仍旧领先,占有率为42.8%。随着Nginx的占有率达到了39.7%,Apache的优势也在不断丧失。
Apache和Nginx的差异包括:
Nginx的配置比Apache更为简洁;Nginx的静态处理性能比Apache优秀得多;Apache对PHP支持比较简单,而Nginx需要配合其他后端使用;Apache较为成熟,组件比Nginx要多。
Nginx对一些现代协议的支持较为优秀,这也许是大多数人改用Nginx的原因之一。支持HTTP/2的网站中,有76.8%采用了Nginx,只有2.3%还在使用Apache。考虑到Apache的HTTP/2模块还在“测试中”,这样的局面毫不意外。与之类似,在支持IPv6的网站中,有63.3%运行着Nginx,几乎是Apache使用者的三倍。
Tomcat vs Weblogic/Webspere
Tomcat is a Servlet/JSP container. It is free. It does not support the Java EE 6 container features such as EJB/JPA out of the box. These can be integrated but will not be equivalent to a proper EJB container.
WebLogic Server is a fully loaded EJB container. It has the best server and database connection pooling features in the market. It is easy to build/deploy/debug apps on Weblogic. It's a commercial product and quite expensive at that.
Comparison between Tomcat and Weblogic:
|
Tomcat
|
Weblogic
|
Definition
|
Tomcat is a web container that runs the web applications based on servlet and JavaServer pages. It can also be used as a HTTP server.
|
Weblogic Server is owned by Oracle Corporation. Basically, it is a Java Application server which provides a range of services like- Http service, session handling, distributed naming and lookup, etc.
|
Type of Server
|
Web server
|
Application server
|
Ownership
|
Apache Software Foundation
|
Oracle
|
Transaction Management
|
Cannot be done
|
Can be done
|
Supports
|
Http
|
Http and ftp
|
Features
|
-
Released under the Apache license.
-
Developed in an open environment.
-
It supports many mission critical web applications.
-
Apache TomEE is the Java Enterprise Edition of Apache Tomcat. It merges many Java enterprise projects like Apache OpenEJB, Apache OpenWebBeans, Apache OpenJPA, Apache MyFaces and others.
|
-
It is a part of Oracle Fusion Middleware portfolio.
-
It supports Oracle, DB2, Microsoft SQL Server, MySQL Enterprise and other JDBC-compliant databases.
-
It consists of a Java EE platform product family.
-
It is a fast and scalable technology.
|
参考
Difference between Tomcat and Weblogic
Difference between the Apache HTTP Server and Apache Tomcat?
Difference between Apache and Nginx
Web服务器之争:Nginx达到33.3%,而Apache则衰落至不足50%
tomcat 与 nginx,apache的区别是什么