Relationship between nginx and php-fpm, nginxphp-fpm
People can perceive it, but the server cannot perceive it. We call it forward to the proxy server.
There is a server load proxy server in the center of Baidu for reverse proxy access.
This is not perceptible to people, but it is perceptible to servers. We call it a reverse proxy server.
Nginx is a high-performance http and reverse proxy server and an IMAP/POP3/SMTP server.
Php-fpm: Fastcgi Process Manager of php-FastCGI Process Manager. PHP
To know what is PHP-fpm, you must first know what is fastcgi and what is cgi.
Cgi General Gateway Interface, external program (php, python) specification when the Web server is running
In the early days, Web servers only process html static files. When php and other dynamic languages fail to process the files, they need to use the interpreters of various dynamic languages, the communication standard or protocol or interface between the interpreter and the web server is cgi. Each PHP file access will be recorded by a process for processing.
Fastcgi resident cgi, which is always executed after activation, does not take time to fork every time (this is the most criticized fork-and-execute mode of CGI ).
Php-fpm is implemented by FastCGI and provides the process management function.
A process includes two processes: the master process and the worker process.
There is only one master process that listens to the port and receives requests from the Web Server, while the worker process generally has multiple (the specific quantity is configured according to actual needs ), each process is embedded with a PHP interpreter, which is the place where PHP code is actually executed.
Also if a FastCGI process in the PHP-FPM management is down, the PHP-FPM will be based on the user configuration to see whether to restart the completion, the PHP-FPM is more like the manager, and the real convergence of Nginx and PHP is FastCGI Process
The content configured by fastcgi_pass is to tell Nginx where to forward the request after receiving the user request.
So how does nginx and php-fpm work. Listen to the next decomposition.
The above definition through nginx we know that Nginx can not only process http requests, but also reverse proxy.
The following is a simple flowchart.
1. The client accesses the website domain name through the http protocol
2. Nginx accepts the request and routes it to index. php.
3. Load fastcgi Module
4. Fastcgi listening 127.0.0.1: 9000 address
5. Then the access will arrive at 127.0.0.1: 9000
6. php-fpm listens to 127.0.0.1: 9000 and receives the request.
7. The master process of Fpm, allocating sub-processes to process requests
8. After processing is complete, return the result to nginx
9. Nginx responds to the client through the http protocol
Nginx is responsible for carrying the response and return of HTTP requests, as well as HTTP-related functions such as timeout control logs, while PHP is responsible for processing the business logic of specific requests, these two cooperation modes are also common in Hierarchical Architecture Design. FastCGI works well together with each other to ensure upstream-downstream communication interaction.
View the fpm process, which can be divided into the master process and sub-process
Ps-ef | grep fpm