Home >Backend Development >PHP Tutorial >Comparison of two deployment methods of Nginx and PHP

Comparison of two deployment methods of Nginx and PHP

WBOY
WBOYOriginal
2016-07-29 09:12:531009browse

Introduction to 2 deployment methods

The first one

  • 1 nginx server in front for HTTP reverse proxy and load balancing
  • Nginx of the N server behind it does web service and calls php-fpm The fast cgi service provided
  • This kind of deployment method is the most common. The web service and the PHP service are deployed on the same server

The second type

  • An nginx server is placed in the front for web service
  • Back The server only deploys the php-fpm service for the nginx server to call.
  • An nginx server is placed in front. When calling multiple php-fpm services later, load balancing can also be achieved.

As shown below:

Nginx 和 PHP 的两种部署方式比较

Comparison

From a system design perspective

The first deployment method is the conventional deployment method, which can be applied to large, medium and small-scale websites.

The second method is to deploy different services on different servers, which is more detailed. But there are also several problems:

  • Front-end nginx acts as a web service. Access to static resources, compression transmission, cache settings, etc. are also concentrated on this server. There will be a lot of pressure and it can easily become a bottleneck.
  • If the static resources are all stored in CDN and do not require HTTP compression transmission, this deployment method is quite reasonable;
  • Undertaking the above two points, this deployment method can also be optimized. For example, nginx load balancing and reverse proxy are placed in the front, nginx web service is in the middle, and php-fpm service is deployed behind.

From a performance perspective

Compared with the second deployment method, the first method requires one more inter-process interaction.

  • According to the first deployment, when an http request comes, first the nginx reverse proxy forwards it to the nginx web service (through the network), and the web service interacts with php-fpm through the fastcgi protocol (inter-process interaction);
  • According to the second deployment, when an http request comes, nginx, which acts as a web service, interacts directly with php-fpm through the network

In the first deployment, the interaction through the network is the HTTP protocol, and in the second type, the interaction through the network It is the fast-cgi protocol. How do these two protocols compare?

  • Fast cgi data packets will be slightly larger than HTTP, and fast cgi protocol will carry more parameter information, transmission control information, etc. than HTTP.
  • fast cgi protocol is more strictly formatted than HTTP protocol and is faster to parse.

From an operation and maintenance perspective

  • The first is the most common deployment method, which is simple and unified. The services on all servers that provide web services are isomorphic, monotonous and extensive.

  • The second method is to deploy nginx and php-fpm separately, and the distribution of different services on the server cluster is more detailed. If you count the pressure distribution in Web services, you can make more precise use of hardware resources. Operation and maintenance costs are also higher.

From a development and testing perspective

Both deployment methods are not suitable for development or testing environments.

In the development and testing environment, nginx and PHP can be deployed on one server. Reverse proxy and load balancing are not required.

Summary

If it is a LAMP environment deployment, the first type is more common.

If it is not LAMP, it is nginx interacting with other fastcgi services, such as C/C++ and java fastcgi programs. In large-scale network applications, deployment similar to the second one is common. Separate deployment of different services simplifies the network structure of the system and makes maintenance easier.

Postscript

The content of this blog post comes from discussions with former Baidu colleagues in the QQ group.

Please indicate the source when reprinting

Blog homepage: Zuocheng’s technical blog

Article title: "Nginx Comparison with two deployment methods of PHP》

Link to this article: http://it.zuocheng.net/compare-2-nginx-php-deployee-mode-zh


The above has introduced the comparison of the two deployment methods of Nginx and PHP, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn