The comparison between Apache and Ngnix

Source: Internet
Author: User
Tags epoll nginx server
php in Apache and Ngnix under the operating mode.

1), Apache under three modes of operation: CGI mode, modular mode, fastcgi mode.

The CGI mode will is a relatively primitive way, every time the request will call Php.exe, parse php.ini, load DLL, etc., speed naturally slow.

Modular mode, Apache by default in this way to run PHP, which is to compile PHP into its own module, in the process of PHP scripts do not need to call the Php.exe program, the entire process is only Apache process processing, relatively stable.

fastcgi mode is an upgraded version of CGI mode, implement a similar connection pool technical features, maintain a connection to the background, the request comes to use, the end is ready to be disconnected from the next request connection, unlike the original CGI mode needs to be called every time .

blocking, creating a process for each request, unlike Nginx, which can process multiple requests with the same process.

2), in the Nginx server does not support CGI, the default in fastcgi mode , and because it is asynchronous non-blocking type, so high concurrency scenarios are supported .

Two, the advantages of nginx versus Apache : 1, lightweight, the same Web services, than Apache Consumes less memory and resources 2, anti-concurrency, Nginx processing request is asynchronous non-blocking, and Apache is blocked (synchronous multi-process) in high concurrency, nginx can keep low resource consumption high performance 3, highly modular design, writing modules Relatively simple 4, community active, a variety of high-performance modules produced quickly ah

Third, the advantages of Apache versus Nginx :

1, rewrite, more powerful than Nginx rewrite

2, for the dynamic page processing performance than Nginx good

3. The module is too much, the basic thought can be found

4, fewer bugs, Nginx bug is relatively more

5. Ultra-Stable

Existence is the reason, in general, Web services that require performance, using Nginx. If performance is not required for stability, then Apache it. 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.


Iv. as a WEB server: use fewer resources than Apache,nginx thanks 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 with C Whether the system resources are open The efficiency of the PIN or CPU is much better than Perlbal. as a mail proxy: 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 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 startup is particularly easy, and can be almost uninterrupted operation, even if the run for several months No reboot is required. You will also be able to upgrade the software version without interruption of service.


Five, Nginx configuration concise, Apache complex Nginx static processing performance 3 times times higher than Apache Apache support for PHP is relatively simple, Nginx needs to cooperate with other backend Apache has more components than Nginx now Nginx is the preferred Web server


Six, the most important difference is the Apache is a synchronous multi-process model One connection corresponds to a process; Nginx is asynchronous , multiple connections (million levels) can correspond to a process


Seven, the nginx processing static files 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 way.

Apache does not support multi-core to download the Chicken rib shortage, recommend using Nginx to do the front end, the back end with Apache. Large Web site suggestions on how to configure the Lnmpa with Nginx generation, you can view the http://www.freehao123.com/lnmpa/

Eight, 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 changed configuration can-T test configuration is not a problem, the Apache restart when the configuration error found, will be very broken, change will be very cautious now see a lot of cluster station, front end nginx anti-concurrency, back-end Apache cluster , the match is also good.


Nine, nginx processing dynamic request is a chicken, General dynamic request to Apache to do, nginx only suitable for static and reverse 。 Ten, from my own experience to see, Nginx is a very good front-end service, load performance is excellent , the old Ben on the Nginx, with webbench simulation of 10,000 static files please do not have the difficulty. Apache's support for languages such as PHP is good, and Apache has a strong support network, which is more time-intensive than Nginx, The main two points of Nginx are superior to Apache: The 1.Nginx itself is a reverse proxy server 2.Nginx supports 7-tier load balancing The other of course, Nginx may be more concurrent than Apache support, but according to Netcraft statistics, April 2011 of statistics, Apache still occupies 62.71%, and Nginx is 7.35%, so in all, Aapche remains the first of most companies because its mature technology and development community has also been a very good performance. 12. 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 processing is slow or the front-end pressure is very high, it is easy to have the Apache process soared, and thus the phenomenon of denial of service. 13, 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 don't bother updating to nginx or learning new things. 14, for Nginx, I like it Configuration file is 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 13, Apache has an advantage in processing dynamics, Nginx concurrency is good, CPU memory consumption is low, if rewrite frequent, it is Apache bar


Copyright notice: This article for Bo Master original article, without Bo Master permission not reproduced.

Above describes the comparison between Apache and Ngnix, including aspects of the content, you want to be interested in PHP tutorial friends helpful.

  • 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.