Why do we use Nginx instead of Apache?

Most of our customers use Apache as a Web server on their servers, especially in the deployment of a PHP-based front-end system and the use of mod-PHP. In view of the expansion and performance reasons, we usually advise them to switch to Nginx and FPM. Apache Web server is very powerful, modular structure, is also the originator of Web server. In addition to the bundled some other tools outside, Apache has become the world's most widely deployed open source system, until recently, most of the world still run the Apache site system. A typical network application server consists of two parts. The client is responsible for the connection section is connected to the user's browser HTTP, to maintain long TCP / IP protocol, usually 1-2 minutes. For a large system, the server may have to bear and deal with at the same time tens of thousands of concurrent connections. This is a direct process that is the upper limit of only 500 500 HTTP connection processing capacity in conflict with Apache. And today's browsers make this problem worse, Because now the average browser will open six sites host links (links two sites a few years ago). So when more than 100 users simultaneously access, Apache has a full load. The second part is the application processing section, which bear the operation code. In most systems, this part of the work is consuming the most CPU and RAM resources, so the number of processes must be strictly limited, usually about 10 per 1GB of memory processes, or two core processes each CPU. Therefore, a 4GB RAM, 16 core server can only run 32 application process. However, the key question is, Apache directly connected to front-end client communications components and back-end application process component. As a result, the front end portion tends to stay connected for a long time, and often reaches a few minutes, which led to the back-end part will continue to consume memory and CPU resources. There is no direct way to find the balance of the front and rear end services in large systems, so they must be separated. There are two main solutions. The first method is the easiest way to existing systems, is installed in the front end load balancing Apache server or client to process Nginx connecting portion. Load balancing server, like HAProxy or Nginx can easily handle thousands of concurrent connections, and Apache can really only work as a back-end application to handle 32 or more processes. The second option is the most common way is to replace Apache with Nginx, while using PHP-PFM as an application server. As mentioned previously, it will split the front end and a rear end portion of the communication client application section. Nginx HTTP protocol processing, while the FPM handle the back-end part of the application, and that 32 processes interact. However, these methods still there are some problems, mainly how to load RPC call to the server, and how to release the RPC call has been completed. Both issues will be explain in subsequent blog. In addition, only Nginx solution to those applications that will rely heavily on Apache functions cause problems, especially particularly dependent on rewrite rules, .htaccess, Or the application of some optional components mod_security like. In this case, the front end of the Apache Nginx increase the installation is the best way. Generally speaking, all new systems should use Nginx and PHP-FPM to deploy. This growth can provide high performance characteristics, and is the best choice and balance of user memory, CPU resources. Existing systems can be used in front-end Nginx or HAProxy to achieve the same effect, in order to provide better service for users in today's modern network environments.

Reproduced in: https: //my.oschina.net/766/blog/211320

Guess you like

Origin blog.csdn.net/weixin_34062469/article/details/91548042