Web server is a key factor that directly affects the performance of the website, and it is an inevitable problem for every webmaster to choose the operating environment of the website. At present, the Web Server market products are numerous, the most mainstream and representative of the Apache,Nginx and Microsoft IIS. The purpose of this article is to compare Apache and Nginx to help users choose the right Web server for them.
First, IntroductionApache:
Apache was founded in 1995 , and has been developed in the Apache Software Foundation since 1999 . Apache is flexible, efficient, has a wealth of expansion modules, and active community support, become the world's most mainstream open source free Web Server software.
Nginx:
Nginx is a free open source Web Server written by Russian software engineer Igor Sysoev . Since its IPO in 2004 ,Nginx has focused on high performance, high concurrency and low memory usage. And its features in load balancing, caching, access and bandwidth control, as well as efficient integration with various applications, make it gradually favored by the majority of users.
The following is a 4 -month update of the Web server market share comparison chart:
650) this.width=650; "Src=" Http://blog.cnezsoft.com/data/upload/201705/f_c3b396ef7e6181725753813a140e1e09.png " Style= "border:1px solid RGB (229,229,229) vertical-align:middle;margin:10px 10px 10px 0px;padding:3px;"/>
Data source:https://news.netcraft.com/archives/2017/04/21/april-2017-web-server-survey.html
Second, contrast
Although Apache and Nginx each have different backgrounds, their purpose is consistent, simply by receiving a user request, then processing the request, and finally returning the processing result to the user.
1.Link Processing
The biggest difference between Apache and Nginx is the way they handle connections. Apache provides a series of multiprocessing modules that use the resources of the operating system, manage processes and thread pools, and control the processing of user requests through these multiprocessing modules.
Apache provides three kinds of multi-processing modules:mpm_prefork,mpm_worker,mpm_envent, below we do a brief explanation of the comparison.
mpm_prefork : The module produces a number of sub-processes, each of which is single-threaded, and each line subroutines a request, such a one-on relationship. So if the number of requests is greater than the number of processes, the performance of the server is unsatisfactory.
650) this.width=650; "Src=" Http://blog.cnezsoft.com/data/upload/201705/f_681cbba888bfa74214030c689c471982.png " Style= "border:1px solid RGB (229,229,229) vertical-align:middle;margin:10px 10px 10px 0px;padding:3px;"/>
Mpm_worker : Unlike prefork ,worker neutron processes are multithreaded, and each thread manages a user connection. The number of threads is more than the number of processes, which means that a new connection can immediately get an idle thread without waiting for the process to be idle.
650) this.width=650; "Src=" Http://blog.cnezsoft.com/data/upload/201705/f_d519a9df519a538ca8955b94b888a2c6.png " Style= "border:1px solid rgb (229,229,229); vertical-align:middle;margin:10px 0px;padding:3px;"/>
mpm_event : This module is similar to the worker , except that the event can handle long connections (keep-alive)to avoid wasting resources when the threads are being requested for long periods of time. It also enhances the request processing capability in high concurrency scenarios.
650) this.width=650; "Src=" Http://blog.cnezsoft.com/data/upload/201705/f_95b74d3b1b9d2a6ad2574071c325c10a.png " Style= "border:1px solid rgb (229,229,229); vertical-align:middle;margin:10px 0px;padding:3px;"/>
Unlike Apache ,Nginx is implemented in an asynchronous, non-blocking, event-driven manner. Nginx 's work process is single-threaded, and each thread can handle a large number of user requests asynchronously. Here's how Nginx works:
650) this.width=650; "Src=" Http://blog.cnezsoft.com/data/upload/201705/f_9d93a8dc6d85ebed8d49247664eea4df.png " Width= "height=" 311 "title=" "style=" border:1px solid rgb (229,229,229); vertical-align:middle;margin:10px 0px; padding:3px; "/>
Image source:http://www.aosabook.org/en/nginx.html
2.processing of static and dynamic content
Whether it's static or dynamic content,Apache can handle it,Apache has built-in parsing and execution of various dynamic scripting languages (including PHP,Python and Perl ), without the need for external processors.
There is no doubt that dynamic content processing is an Nginx pain point. Nginx is not efficient at handling dynamic content and requires external processors. So if your site has a lot of dynamic features,Apache 's performance may be more relevant to you. However, although Nginx 's dynamic content processing ability is poor compared with Apache , its static content processing is very efficient.
Iii. Summary
Apache with rich module component support, stable and strong, BUG , dynamic content processing is strong.
Nginx lightweight, less resource-intensive, load-balanced, high concurrency-intensive, and efficient for static content processing.
There is a reason,Apache and Nginx as a WEB service strengths, personally think that there is no future who will completely replace who. The key is that users should seriously consider their own application scenarios, according to their own needs and circumstances to choose which products, suitable for their own is the best.
This article is from the "12379180" blog, please be sure to keep this source http://12389180.blog.51cto.com/12379180/1924879
How does the Web server choose Apache or Nginx?