Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Nginx and PHP are deployed

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the deployment of Nginx and PHP". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the deployment of Nginx and PHP"?

Brief introduction of two deployment methods

First kind

A front nginx server to do http reverse proxy and load balancing

The nginx of the later n-server does the web service and invokes the fast cgi service provided by php-fpm

This kind of deployment is the most common. Both web service and php service are deployed on the same server.

The second kind

1 nginx server in front to do web service

Later servers only deploy php-fpm services for nginx servers to call

With a nginx server in front, you can also achieve load balancing when calling multiple php-fpm services.

The figure is as follows:

Contrast

From the perspective of system design

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

Second, different services are deployed on different servers and are more detailed. But there are a few problems:

The front nginx acts as a web service. Access to static resources, compression transmission, cache settings, and so on, are also concentrated on this server. The pressure will be great, and it is easy to become a bottleneck.

If static resources are stored in cdn and do not need http compressed transmission, this kind of deployment is reasonable.

Following the above two points, you can also optimize this deployment. Such as the front nginx load balancer and reverse proxy, the middle is the nginx web service, and then the php-fpm service is deployed. From a performance point of view

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

According to the first deployment, when a http request comes, the nginx reverse proxy is forwarded to the nginx web service (over the network), and the web service interacts with the php-fpm through the fastcgi protocol (inter-process interaction).

According to the second deployment, when a http request comes, it acts as the nginx of the web service and interacts directly with the php-fpm through the network.

The first deployment is the http protocol that interacts over the network, and the second is the fast-cgi protocol that interacts over the network. how do these two protocols compare?

The packet of fast cgi will be slightly larger than that of http, and fast cgi protocol will carry more parameter information, transmission control information and so on than http. Fast cgi protocol is more strictly formatted and faster to parse than http protocol. From the perspective of operation and maintenance

The first is the most common way of deployment, which is simple and unified, and the services on all servers that provide web services are isomorphic 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 stress distribution in web services, you can use hardware resources more finely. Operation and maintenance costs are also higher.

From the perspective of development and testing

Neither deployment method is suitable for the development or test environment.

The development and test environment can deploy nginx and php to a single server without reverse proxy and load balancing.

Thank you for your reading, the above is the content of "what is the deployment of Nginx and PHP". After the study of this article, I believe you have a deeper understanding of the deployment of Nginx and PHP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report