Comparison of the advantages and disadvantages of Nginx and Apache

Source: Internet
Author: User
Tags epoll cpu usage hosting nginx server

The simple thing is that Apache httpd and Nginx are Web servers, but the two adapt to different scenarios, that is, the two focus on solving different problems. Apache httpd: Stable, strong dynamic request processing, but at the same time high concurrency performance is weak, consuming more resources. Nginx: High concurrency processing ability, good at handling static requests, reverse proxy, balanced load. In this article detailed list of Apache and Nginx 13 similarities and differences, the following we will analyze the principle of each.

1,nginx compared to the advantages of Apache: Lightweight, the same Web services, more than Apache occupy less memory and resources, anti-concurrency, Nginx processing requests are asynchronous non-blocking, and Apache is blocking type, in high concurrency under the Nginx Can keep low resource consumption high performance, highly modular design, writing modules relatively simple, community active, a variety of high-performance modules produced quickly AH

Apache relative to the advantages of Nginx: Rewrite, more powerful than Nginx rewrite, more modules, the basic thought can find less bugs, Nginx bug relatively more ultra-stable. Existence is the reason, in general, the need for performance of Web services, with Nginx. If you don't need performance for stability, then Apache. The latter of the various functional modules implemented than the former, such as the SSL module is better than the former, more configurable items. One thing to note here is that Epoll (FreeBSD is kqueue) network IO Model is the fundamental reason for the high performance of nginx processing, but not all cases are epoll victory, if you provide static services only a few files, Apache Select Models may be more performant than Epoll. Of course, this is just a hypothesis based on the principle of the network IO model, and the actual application still needs to be measured.

# #对于网络IO复用模型, I do not understand, but reference Baidu encyclopedia to Epoll explained: Epoll is Linux under the Multiplexed IO Interface Select/poll enhanced version, It can significantly increase the CPU utilization of the system in a small number of active cases in large numbers of concurrent connections, because it will reuse the file descriptor collection to pass the result without forcing the developer to prepare a collection of file descriptors to be listened to before each wait for the event, another point is to get the event, It does not need to traverse the entire set of descriptors that are being listened to, as long as it traverses the set of descriptors that are joined to the ready queue by a kernel IO event that wakes up asynchronously. It can be seen from this that Nginx uses epoll than select in theory is more efficient (why theoretically, I give an example, to an O (N) and O (n^2) algorithm, if the size of the data to be processed is 1 or very little, the two can reflect the efficiency difference? The other is that the Select IO model has a limit on the file descriptors that are opened for each process, so I'm just a factor in the performance that affects Apache concurrency.

2, as a WEB server: using less resources than Apache,nginx, supporting more concurrent connections, reflecting higher efficiency, which makes Nginx particularly popular with virtual hosting providers. In the case of high connection concurrency, Nginx is a good alternative to Apache server: Nginx in the United States is a virtual hosting business owners often choose one of the software platform. Capable of supporting up to 50,000 concurrent connections, thanks to Nginx for choosing Epoll and Kqueue as the development model. Nginx as a Load Balancer server: Nginx can either directly support the internal Rails and PHP programs outside the service, also can support as an HTTP proxy server external services. Nginx is written in C, whether it is system resource overhead or CPU usage efficiency is much better than Perlbal. As a mail proxy server: Nginx is also a very good mail proxy server (one of the first to develop this product is also as a mail proxy server), Last.fm describes the success and the wonderful use of experience. Nginx is a very simple installation, the configuration file is very concise (also can support Perl syntax), Bugs very few servers: Nginx boot is particularly easy, and can be almost uninterrupted operation, even if the run for several months do not need to restart. You will also be able to upgrade the software version without interruption of service.

# #nginx比apache支持更高的并发连接, more efficient, and the previous 1th said there are a lot of factors, the network IO model is different, the other is Nginx is asynchronous processing requests, and Apache is synchronous processing, each process corresponds to a request. The disadvantage of Apache using each process corresponds to a request is also discussed later.

3. Nginx configuration Concise, Apache complex, Nginx static processing performance 3 times times higher than Apache, Apache support for PHP is relatively simple, nginx need to cooperate with other backend, Apache more components than Nginx, now Nginx is The preferred WEB server

# #Nginx对动态处理请求弱, this I want to do with its own implementation, it needs to be combined with other modules to support PHP and other languages, and Apache support better, if you find the underlying implementation of the root cause, welcome message Guide ~

4, The most important difference is that Apache is a synchronous multi-process model, a connection corresponding to a process; Nginx is asynchronous, multiple connections (million levels) can correspond to a process

# #两者处理请求的模型不同, the direct result of two points: A>nginx's anti-concurrency ability is much stronger. B>nginx has less demand for resources, because the Apache process corresponds to the request with one by one, the resource requirements are large when the request is large, and the cost of process creation destruction is significant. But now it seems to be improving, prefork can pre-create some processes on demand, which is a bit like the thread pool concept.

5,nginx processing static file is good, consumes less memory. But Apache is undoubtedly still the mainstream, with a lot of rich features. So it needs to be paired. Of course, if you can be sure that Nginx is suitable for your needs, then using Nginx will be a more economical approach.

# #这个应该与前面说的几点都有关系: Nginx uses epoll io multiplexing model; asynchronously processes the request; The thread is a one-to-many relationship with the request.

6, from the personal past use of the situation, nginx load capacity is much higher than Apache. The newest server also changed to Nginx. and Nginx change the configuration can be-t test configuration is not a problem, the Apache restart when the configuration error found, will be very crash, change will be very cautious now see a lot of cluster station, front-end nginx anti-concurrency, back-end Apache cluster, with good.

# #在这点里面, we are mainly concerned about this: Nginx+apache used in combination. Since both have advantages, then we have to avoid weaknesses, Nginx is responsible for anti-concurrency, load balancing, do static file caching, the backend uses Apache processing dynamic requests.

7,nginx processing dynamic request is chicken, general dynamic request to Apache to do, nginx only suitable for static and reverse.

# #nginx处理动态请求是鸡肋的原因谁能从原理方面帮解释一下? Is it because the language support for PHP is not good enough? What is suitable for nginx is static request and reverse proxy, what is reverse proxy? Simply said that the client will be the Nginx server as their target machine, the request to the Nginx machine, as for the Nginx machine is the client needs to obtain from where the resources, the client does not care (there is a difference and forward proxy, in the forward proxy is I can not access the target machine, Because I will send you a request to the agent machine, and then in your name to get the resources I need.

8, from my personal experience to see, Nginx is very good front-end service, the load performance is excellent, in the old Ben on the Nginx, with Webbench simulation 10,000 static file Please do not have the difficulty. Apache support for languages such as PHP is very good, in addition to Apache has strong support network, the development of the time compared to nginx longer, bug less but Apache does not support multi-core deal with the lack of chicken ribs, recommend using Nginx to do the front end, the back end with Apache. Large Web site suggestions for the use of nginx-generation cluster function

# # This is still a good choice to say that Nginx+apache is a combination.

9. Nginx is superior to Apache's main two points: the 1.Nginx itself is a reverse proxy server 2.Nginx support 7 layer load balancing; Of course, nginx may support higher concurrency than Apache, but according to Netcraft statistics, April 2011 Statistics, Apache still occupies 62.71%, and Nginx is 7.35%, so always, Aapche is still the majority of companies first, because its mature technology and development community has also been very good performance.

# #apache早出现, people did not choose, and the small pressure of the Web site with Apache is enough to meet the request pressure, so the market share there is a gap.

10 . Your need for Web server determines your choice. In most cases, Nginx is superior to Apache, such as static file processing, php-cgi support, reverse proxy function, front-end cache, maintenance connection, and so on. In apache+php (prefork) mode, if the PHP process is slow or the front-end pressure is very high, it is easy to get a spike in the number of Apache processes, thereby denying service.

# #apache的缺陷, no pressure, and due to the soaring number of threads, resource demand is also very

11, can look at the Nginx Lua module: Https://github.com/chaoslaw...apache more than Nginx module, can be directly implemented with LUA Apache is the most popular, why? Most people are lazy to update to nginx or learn new things # # ...

12, for Nginx, I like it configuration file written very concise, regular configuration makes a lot of things easy to run high efficiency, less resources, powerful proxy, very suitable for the front-end response server

# #看了一下, nginx configuration file is really more concise and easy to understand

13. Apache in the processing of dynamic has advantages, nginx concurrency is better, CPU memory consumption, if rewrite frequent, it is Apache Bar # #rewrite这点不是很了解, not much to say

Comparison of the advantages and disadvantages of Nginx and Apache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.