Origin:http://www.tuicool.com/articles/ir2aree
Nginx ("Engine X") is a high-performance HTTP and reverse proxy server and a IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev, the second rambler.ru site for Russian visits, and the first public version of 0.1.0 was released on October 4, 2004. It publishes the source code in the form of a BSD-like license, which is known for its stability, rich feature sets, sample configuration files, and low system resource consumption. -Baidu Encyclopedia
When Nginx receives an HTTP request, the corresponding server is found through the configuration file. It then matches all the location in the server and finds the most matching. The commands in location start different modules to complete the work, such as the rewrite module, the index module. Therefore, in the Nginx module can be regarded as a real labor worker. Nginx's modules are compiled into Nginx and are static in their own way. When the Nginx is started, the module is automatically loaded. Unlike Apache, the module is compiled separately into the so file, which specifies whether to load in the configuration file. As a result, Nginx also has a higher speed than Apache in terms of loading the module.
That Nginx is how to invoke PHP. Let's look at the configuration of PHP in the nginx below something
Shell
Location ~ \.php$ {
root /webpath;
Fastcgi_pass 127.0.0.1:9000;
... ...
}
This location instruction takes PHP as the file suffix of the request to 127.0.0.1:9000 processing. I think you see this should be guessed, this is a C/s architecture things. and the IP address and port (127.0.0.1:9000) Here are the IP addresses and ports that the fastcgi process listens to. FastCGI is a scalable, high-speed interface for communicating between HTTP server and dynamic scripting languages. Most popular HTTP servers support FASTCGI, including Apache, Nginx, and lighttpd. At the same time, fastcgi is also supported by a number of scripting languages, including PHP.
So where does this fastcgi configuration IP and port come from? In php-fpm.conf you can see the following: something
Shell
Listen = 127.0.0.1:9000 #这个表示php的fastcgi进程监听的ip地址以及端口
pm.start_servers = 2
PHP-FPM as the FASTCGI process Manager, can effectively control memory and processes, and smooth overload of the PHP configuration. After php5.3, PHP-FPM is integrated into the core of PHP and is installed by default without configuration.
The FASTCGI process Manager php-fpm itself, initiates the main process php-fpm and initiates start_servers fastcgi child processes. The main process PHP-FPM mainly manages the fastcgi subprocess, listens on port 9000, and fastcgi the child process waits for the request. When the client requests to Nginx, nginx through the location instructions, all PHP-suffix files are handed to the 127.0.0.1:9000 to deal with. PHP-FPM selects and connects to a fastcgi subprocess and sends environment variables and standard input to the fastcgi subprocess. Returns standard output and error information after the FASTCGI process finishes processing. When the fastcgi child process closes the connection, the request is processed and waits for the next processing.