面试过程中被问到Apache和Nginx服务器的对比,因为之前没有关注过这个问题,所以也没能回答上来。

今天在网上搜索资料,发现中文资料极少,还是英文资料多一下。

原文链接:https://www.wikivs.com/wiki/apache_vs_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

Apache和Nginx对比的更多相关文章

  1. apache与nginx对比优势及劣势

    1.nginx相对于apache的优点:轻量级,同样起web 服务,比apache占用更少的内存及资源抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能 ...

  2. web网站——apache和nginx对比02

    nginx介绍 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx,它的发音为“engine X”,是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/SMTP 代理 ...

  3. Apache和Nginx比较

    Apache和Nginx对比 功能对比 Nginx和Apache一样,都是HTTP服务器软件,在功能实现上都采用模块化结构设计,都支持通用的语言接口,如PHP.Perl.Python等,同时还支持正向 ...

  4. Apache与Nginx对客户端请求的处理机制对比

    Apache与Nginx对客户端请求的处理机制对比 模块 大致为四个模块,核心模块.HTTP模块.邮件模块,以及第三方模块 核心模块主要包含两类功能的支持,一类是主体功能,包括进程管理,权限管理,错误 ...

  5. PHP服务器Apache与Nginx的对比分析

    PHP服务器Apache与Nginx的对比分析 本篇文章给大家带来的内容是关于PHP服务器Apache与Nginx的对比分析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. Apach ...

  6. 转: 三大WEB服务器对比分析(apache ,lighttpd,nginx) (2008年的旧文,仅供参考之用)

    from:  http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 三大WEB服务器对比分析(apache ,lighttp ...

  7. Apache与nginx优缺点对比

    1.nginx相对于Apache优点: nginx轻量级,同样起web服务,比apache占用更少的内存资源: 抗并发,nginx处理请求是异步非阻塞型的,Apache处理请求是阻塞型的,所以在处理高 ...

  8. [转]三大WEB服务器对比分析(apache ,lighttpd,nginx)

    原博文地址:http://www.blogjava.net/daniel-tu/archive/2008/12/29/248883.html 一.软件介绍(apache  lighttpd  ngin ...

  9. 三大WEB服务器对比分析(apache ,lighttpd,nginx)

    一.软件介绍(apache  lighttpd  nginx) 1. lighttpd Lighttpd是一个具有非常低的内存开销,cpu占用率低,效能好,以及丰富的模块等特点.lighttpd是众多 ...

随机推荐

  1. Java知识回顾 (1) 编译环境与基本变量类型

    参考资料 runoob Java知识回顾序列的相关资料,主要来自 runoob,并对其中的知识进行概况或总结,去除对一个之前了解过Java的人员无关的知识点.以便能够使得一个新手,或之前有Java经验 ...

  2. C#编程(四十八)----------列表

    C#中的List C#中deList怎么样?List<T>类是ArrayList类的泛型等效类,该类使用大小可按需动态增长的数组实现List<T>泛型接口. 泛型的好处:它为使 ...

  3. WebApp分析建模的工具

    最近Web工程课在学习分析建模工具的内容.这周作业就写我对WebApp建模工具的认识.Web建模工具有很多,但是专门为分析开发的却相对很少.下面介绍在进行分析时可以用的四类工具. UML工具.使用统一 ...

  4. RabbitMQ:基本命令

    rabbitmq的安装.启动和停止 rabbitmq-service.bat install rabbitmq-service.bat start rabbitmq-service.bat stop ...

  5. 在SpringMVC中使用Jackson并格式化时间

    在spring MVC 3中,要实现REST风格的JSON服务,最简单的方式是使用 @ResponseBody 注解.该注解会自动把返回的对象,序列化为JSON. 来看一个最简单的例子.这个例子先使用 ...

  6. 大西洋帝国第一季/全集Boardwalk Empire1迅雷下载

    大西洋帝国 第一季 Boardwalk Empire Season 1 (2010) 本季看点:1920年,联邦政府颁布禁酒令后,公开售卖酒类商品成为一种违法行为.在新泽西州的西南部的大西洋城没有任何 ...

  7. 《HTML5与CSS3基础教程(第8版)》

    <HTML5与CSS3基础教程(第8版)> 基本信息 原书名:HTML and CSS:visual quickstart guide 作者: (美)Elizabeth Castro    ...

  8. 【Java并发】JUC—ReentrantReadWriteLock有坑,小心读锁!

    好长一段时间前,某些场景需要JUC的读写锁,但在某个时刻内读写线程都报超时预警(长时间无响应),看起来像是锁竞争过程中出现死锁(我猜).经过排查项目并没有能造成死锁的可疑之处,因为业务代码并不复杂(仅 ...

  9. ConcurrentHashMap和HashMap的区别

    (1)ConcurrentHashMap对整个桶数组进行了分段,而HashMap则没有 (2)ConcurrentHashMap在每一个分段上都用锁进行保护,从而让锁的粒度更精细一些,并发性能更好,而 ...

  10. Focal Loss(RetinaNet) 与 OHEM

    Focal Loss for Dense Object Detection-RetinaNet YOLO和SSD可以算one-stage算法里的佼佼者,加上R-CNN系列算法,这几种算法可以说是目标检 ...