Apache和Nginx对比

简介:

精简版

Apache:出名比较早,09年左右是最流行的时期,功能强大,可以根据需求配置为基于进程,基于线程或者基于事件的,但是消耗内存较多,对硬件需求较高,内存是影响服务器性能的最关键因素,在VPS上不能很好的支持。

Nginx:属于后起之秀,近年来应用越来越广泛,主要特点是低内存消耗,可以很好的运行在VPS上,这是因为Nginx是基于事件的异步服务器,因此在收到新的请求之后,无需新建过多的线程。

Nginx并发数高,处理请求异步非阻塞,一个进程多个连接,而Apache是同步多进程,一个进程一个连接,属于阻塞型。

Nginx占用资源和内存小,高度模块化,配置简单,Apache的配置就相对复杂了。

Nginx适合处理静态文件和反向代理。

Apache的Rewrite功能更加强大,对动态页面支持更好,超级稳定。

Apache对PHP支持比较简单,Nginx需要配合其他后端使用,Apache的组件也更加丰富。

一般前端是Nginx,后端是Apache。

参考资料

[1]http://4921679.blog.51cto.com/4911679/1192611

[2]http://www.cnblogs.com/huangye-dream/p/3550328.html

完整版

Both Apache and nginx(pronounced “engine-x”) are free, open-source, cross-platform web servers.

The Apache HTTP Server, commonly referred to asApache, is a web server notable for playing a key role in the initial growth of the World Wide Web. [...] In 2009 Apache became the first web server to surpass the 100 million web site milestone. [...] Since April 1996 Apache has been the most popular HTTP server on the World Wide Web. As of March 2009, Apache served over 46% of all websites and over 66% of the million busiest.

nginx is noted to be a good server for sites that need fast, efficient reverse proxies [1], [2], [3]or fast, efficient serving of static content [4]. It is acclaimed for having low memory usage and is recommended for sites running on a VPS[5].

Architecture

Apache is a flexible server which can be process-based, thread-based or event-based as determined by the MPM used, while nginx is an event-based web server.

Nginx and Lighttpd are probably the two best-known asynchronous servers and Apache is undoubtedly the best known originally process-based server. The main advantage of the asynchronous approach is scalability. In a process-based server, each simultaneous connection requires a thread which incurs significant overhead. An asynchronous server, on the other hand, is event-driven and handles requests in a single (or at least, very few) threads.

While a process-based server can often perform on par with an asynchronous server under light loads, under heavier loads they usually consume far more RAM which significantly degrades performance. Also, they degrade much faster on less powerful hardware or in a resource-restricted environment such as a VPS.

Features

Like Apache, Nginx has all the features you would expect from a leading Web server:

  • Static file serving.
  • SSL/TLS support.
  • Virtual hosts.
  • Reverse proxying.
  • Load balancing.
  • Compression.
  • Access controls.
  • URL rewriting.
  • Custom logging.
  • Server-side includes.
  • Limited WebDAV.
  • FLV streaming.
  • FastCGI.

It is stable, secure and very easy to configure, as you will see later in the article. However, the main advantages of Nginx over Apache are performance and efficiency.Whether you are looking to get the most out of your VPS or are attempting to scale one of the largest Web sites in the world, Nginx may be the best tool for the job. It's fast, stable and easy to use.

According to the Wikipedia article "Comparison of web servers", Apache has the following extra features compared to nginx:

  • administrative console
  • .htaccess

 

I mentioned earlier that nginx isn’t very suited for shared hosting. You might think that if you let nginx handle just static files while proxying non-existing files and dynamic files to Apache then you’ll be good. This isn’t quite the case, though. As an example, consider basic authentication, if you want to have basic authentication on a static file then you will need to add it in the nginx configuration, and users cannot do this without having to reload the configuration file. If you allow them to change it and reload it then they can make a mistake and ruin it for everyone.

[6]

Performance

Nginx is faster at serving static files and consumes much less memory for concurrent requests. Because Nginx is event-based, it doesn't need to spawn new processes or threads for each request, so its memory usage is very low.

Wordpress.com has found nginx to be the only load balancer able to handle 8000 live traffic requests per second.[7]

The only solution I know of that's extremely high performance that offers all of the features that you want is nginx [...] I currently have nginx doing reverse proxy of over tens of millions of HTTP requests per day (thats a few hundred per second) on a *single server*. At peak load it uses about 15MB RAM and 10% CPU on my particular configuration (FreeBSD 6).

Under the same kind of load, apache falls over (after using 1000 or so processes and god knows how much RAM), pound falls over (too many threads, and using 400MB+ of RAM for all the thread stacks), and lighty *leaks* more than 20MB per hour (and uses more CPU, but not significantly more).

 Bob Ippolito ,  TurboGears mailing list, 2006-08-24

Ease of use

Configuration Tools [of nginx] is a cinch and deployment was easy as pie.

[nginx] is stable, secure and very easy to configure, as you will see later in the article.

 Nginx: the High-Performance Web Server and Reverse Proxy ,  Linux Journal, September 2008

We were using Pound for load balancing at Justin.tv until today. It was consistently using about 20% CPU, and during spikes would use up to 80% CPU. Under extremely high load, it would occasionally freak out and break.

We just switched to Ngnix, and load immediately dropped to around 3% CPU. Our pages feel a little snappier, although that might be my imagination. Not only is the config format easier to understand and better documented, but it offers a full webserver's complement of functionality.

Popularity

In 2009 Apache became the first web server to surpass the 100 million web site milestone. [...] Since April 1996 Apache has been the most popular HTTP server on the World Wide Web. As of March 2009, Apache served over 46% of all websites and over 66% of the million busiest.

Apache's web server market share is increasing again since early 2010, and Nginx has been more or less stable for a while now (since late 2009), according to Netcraft web server surveys for July 2011.

External Links

 


本文转自ZH奶酪博客园博客,原文链接:http://www.cnblogs.com/CheeseZH/p/5168360.html,如需转载请自行联系原作者

相关文章
|
Java 应用服务中间件 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
199 2
简介Nginx,Tomcat和 Apache
|
11月前
|
缓存 前端开发 应用服务中间件
CORS跨域+Nginx配置、Apache配置
CORS跨域+Nginx配置、Apache配置
538 7
|
缓存 应用服务中间件 Apache
为什么 Nginx 比 Apache 更牛叉?
本文介绍了Nginx在处理高并发方面的优势和工作原理。与Apache相比,Nginx在处理大量并发静态请求时效率更高,并能轻松解决C10K问题。文章详细讲解了Apache的三种工作模式(prefork、worker、event)以及它们的工作原理,然后介绍了Nginx如何提高Web服务器的并发连接处理能力。Nginx支持基于线程、事件驱动、异步和非阻塞的架构,通过多路复用和事件通知机制处理并发连接和请求。同时,Nginx的轻量化特性使其消耗较少的内存和CPU资源,可以高效地处理可以高效地处理海量并发连接。内容转载至https://www.sohu.com/a/653374147_1211243
|
Web App开发 应用服务中间件 网络安全
如何在 Apache 和 Nginx 上配置 OCSP Stapling
如何在 Apache 和 Nginx 上配置 OCSP Stapling
362 9
|
Ubuntu 应用服务中间件 Linux
在Linux中,如何配置Web服务器(如Apache或Nginx)?
在Linux中,如何配置Web服务器(如Apache或Nginx)?
|
负载均衡 应用服务中间件 Apache
Nginx与Apache的终极对决:揭秘Web服务器界的“速度与激情”!你不可不知的性能霸主如何颠覆传统,震撼互联网的根基!
【8月更文挑战第13天】互联网技术发展中,Web服务器至关重要,Nginx与Apache是最广泛使用的两种。Apache历史悠久,但Nginx以轻量级和高性能脱颖而出。Nginx采用事件驱动架构,高效处理大量并发连接,而Apache使用进程驱动,高并发下资源消耗大。以餐厅为例,Nginx像大堂经理同时处理多个顾客需求,远比Apache为每位顾客分配服务员更高效。性能测试显示Nginx处理能力远超Apache。此外,Nginx配置简洁灵活,尤其在负载均衡方面表现突出。尽管Apache适合动态内容处理,但在快速变化的互联网环境中,Nginx因其独特优势成为许多开发者和企业的首选。
186 7
|
前端开发 应用服务中间件 网络安全
nginx和apache的区别
Nginx是轻量级、抗并发的服务器,擅长静态文件处理和反向代理,配置简洁,适合高流量场景。 Apache采用同步多进程模型,功能丰富,对动态请求处理强,SSL支持好,适合复杂的企业级应用。 根据需求,高并发选Nginx,丰富功能和稳定性考虑Apache。两者也可结合使用,Nginx作为前端代理,Apache处理后端请求。
246 3
|
应用服务中间件 Linux 网络安全
在Linux中,如何配置Apache或Nginx Web服务器?
在Linux中,如何配置Apache或Nginx Web服务器?
|
Ubuntu 应用服务中间件 Linux
在Linux中,如何查看Apache或Nginx服务的状态?
在Linux中,如何查看Apache或Nginx服务的状态?
|
应用服务中间件 Apache nginx
apache、nginx开启rewrite重写服务及伪静态
apache、nginx开启rewrite重写服务及伪静态
596 4

推荐镜像

更多