nginx is a high performance http and reverse proxy server, but also a IMAP / POP3 / SMTP server
Php-fpm:. Php-Fastcgi Process Manager PHP's FastCGI Process Manager
To know what is PHP-fpm, we must first know what is fastcgi, but also to know what is cgi
Cgi Common Gateway Interface, Web servers running external programs (php, python) specification
Early Web server only handles static html file, when php and other dynamic languages appear not handle, you need to use an interpreter various dynamic languages, so communication standard or protocol between the interpreter and the interface is a web server or cgi. Every visit to the complex php files will carve a process for processing
Permanent type cgi Fastcgi, just after activation, has been executed, will not always have to take the time to fork once (this is the most criticized CGI fork-and-execute mode).
php-fpm is to achieve FastCGI, and provides a process management functions.
Process contains master process and worker processes two kinds of processes.
Only one master process, responsible for monitoring port, receives requests from Web Server, and the worker process is generally more (specific number according to the actual needs), are embedded within each process a PHP interpreter, PHP code is actually executed The place.
And if a FastCGI process under the management of PHP-FPM hung up, PHP-FPM will make the user whether to restart the whole configuration point of view, PHP-FPM is more like a manager, while the real convergence of Nginx and PHP is FastCGI process
Content configured fastcgi_pass, is to tell Nginx after you receive a user request, you where to go forward
So nginx and php-fpm in the end is how it works. Please listen the next time decomposition.
Defined by nginx we know, Nginx does not only processing http requests, but also do the reverse proxy.
Simple flow
1. The client via http protocol to access domain
2. Nginx accepts the request and routed to index.php
3. Load fastcgi module
4. Fastcgi listening 127.0.0.1:9000 address
The access then reaches 127.0.0.1:9000
6. php-fpm monitor 127.0.0.1:9000, it receives the request
7. master Fpm main process, the child process assigned to process the request
8. After the processing is complete, return the results to nginx
9. Nginx response to the client via the http protocol
Nginx responsible for carrying response returns an HTTP request and HTTP timeout control logging and other related functions, and PHP is responsible for processing business logic specific request to do, this mode of cooperation the two of them are also common layered architecture design in one, while they have focused plane, FastCGI and good convergence of the two, to protect the downstream communication interaction