Comparison of Nginx and PHP deployment methods

Source: Internet
Author: User
Tags nginx reverse proxy nginx load balancing
: This article mainly introduces the comparison of Nginx and PHP deployment methods. if you are interested in the PHP Tutorial, refer to it. Introduction to two deployment methods

First

  • Front-end nginx server for HTTP reverse proxy and load balancing
  • Nginx on the backend is used as a Web service and the fast cgi service provided by php-fpm is called.
  • This deployment method is the most common. web services and PHP services are deployed on the same server.

Second

  • Front-end nginx server for Web services
  • The following servers only deploy the php-fpm service for the nginx server to call.
  • A front-end nginx server can also achieve load balancing when calling the following multiple php-fpm services

For example:


Comparison

From the perspective of system design

The first deployment method is the conventional deployment method, which can be applied to websites of large and small sizes.

Second, different services are deployed on different servers, which is more detailed. But there are also several problems:

  • The front-end nginx acts as a Web service. Access to static resources, compression and transmission, and cache settings are also concentrated on this server. The pressure is high and it is easy to become a bottleneck.
  • If static resources are stored in CDN and HTTP compression is not required, this deployment method is reasonable;
  • Take over the above two points, you can also optimize this deployment method. For example, for front-end nginx load balancing and reverse proxy, the nginx Web service is in the middle, and the php-fpm service is deployed later.

Performance

Compared with the second deployment method, the first one takes one more interaction between processes.

  • According to the first deployment, when an http request comes over, the nginx Reverse proxy is first forwarded to the nginx Web service (through the network ), web services then interact with php-fpm through the fastcgi protocol (inter-process interaction );
  • According to the second deployment, when an http request comes, nginx acts as a Web service and interacts directly with php-fpm through the network.

In the first deployment, HTTP protocol is used for network interaction, and fast-cgi protocol is used for network interaction. how are the two protocols compared?

  • Fast cgi data packets are slightly larger than HTTP data packets, and the fast cgi protocol carries more parameter information and transmission control information than HTTP.
  • The fast cgi protocol is more rigorous than the HTTP protocol, and the parsing speed is faster.

From the O & M perspective

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

  • 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 count the pressure distribution in Web services, you can use hardware resources more precisely. The O & M cost is also higher.

From the perspective of development and testing

Both deployment methods are not suitable for the development environment or test environment.

Deploy nginx and PHP on a server in the development and testing environment without reverse proxy and server load balancer.

Summary

For LAMP environment deployment, the first is more common.

If it is not LAMP, nginx interacts with other fastcgi services, such as C/C ++ and java fastcgi programs. similar to the second deployment is common in large-scale network applications. Different services are deployed separately, which simplifies the network structure of the system and facilitates maintenance.

Postscript

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

Reprinted please indicate the source

Blog Homepage: Cheng's technical blog

Article title: Comparison of Nginx and PHP deployment methods

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


The above describes the two deployment methods of Nginx and PHP, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.

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.