This article mainly introduces the details of Nginx and php.cn/"target=" _blank ">php of the two methods of deployment of the relevant data, the need for friends can refer to the following
A comparison of two deployment methods for Nginx and PHP
Introduction to 2 ways to deploy
First Kind
Front 1 nginx servers do HTTP reverse proxy and load balancing
Behind n-server nginx do Web services and invoke the fast CGI service provided by PHP-FPM
This type of deployment is most common, and Web services and PHP services are deployed on the same server
The second Kind
Front 1 nginx server to do Web service
The subsequent server only deploys the PHP-FPM service for the Nginx server to invoke
Front 1 Nginx server, can also be used to load balance when invoking multiple PHP-FPM services
Such as:
Contrast
From the point of view of system design
The first deployment is general deployment, and large and medium-sized websites can be used.
Second, different services are deployed on different servers and are more granular. But there are also several questions:
The front-facing Nginx acts as a Web service. Access to static resources, compressed transport, cache settings, and so on, are also concentrated on this server. The pressure will be big, easy to become the bottleneck.
If the static resources are stored in the CDN, do not need the HTTP compression transmission, this kind of deployment method is more reasonable;
The above two points can also be optimized for this type of deployment. such as pre-nginx load balancing and reverse proxy, the middle is the Nginx Web service, behind the deployment of PHP-FPM services. From a performance perspective
Compared to the second deployment method, the first one has to go through inter-process interaction.
According to the first deployment, when an HTTP request comes in, the Nginx reverse proxy is forwarded to the Nginx Web service (through the network), and the Web service interacts with the PHP-FPM via the FASTCGI protocol (inter-process interaction);
Following the second deployment, when an HTTP request comes in, it acts as a Web service Nginx, directly interacting with the PHP-FPM through the network
The first kind of deployment, through the network to interact with the HTTP protocol, the second through the network interaction is the FAST-CGI protocol, the two kinds of protocol comparison?
Fast CGI packets are slightly larger than HTTP, and the fast CGI protocol carries more parameter information, Transmission control information, and so on than HTTP. The fast CGI protocol is more restrictive than the HTTP protocol and is faster to parse. From an operational perspective
The first is the most common deployment method, simple unification, all the services provided by the Web services on the server are isomorphic, monotonous and extensive.
The second is to deploy Nginx and PHP-FPM separately, and the distribution of different services on the server cluster is more detailed. If you are counting the stress distribution in a Web service, you can use hardware resources more finely. Operation and maintenance costs are also higher.
From the perspective of development testing
Neither deployment is appropriate for either the development environment or the test environment.
The development and test environment deploys nginx and PHP to a single server, without the need for reverse proxy and load balancing.
Summarize
If the lamp environment is deployed, the first is more common.
If it is not lamp, it is nginx and other fastcgi services interaction, such as C + +, Java fastcgi program, in large-scale network applications, similar to the second kind of deployment is common. To do separate deployment between different services, but simplifies the network structure of the system, more convenient maintenance.