PHP + FastCGI + Nginx dynamic request processing configuration Nginx does not support calls to external programs. Therefore, you must use the FastCGI interface to call external programs to process client dynamic page requests.
CGI is called the Common Gateway Interface (public Gateway Interface) in English and serves as a bridge between Nginx and dynamic scripting programs. Nginx sends dynamic requests to FastCGI through the FastCGI Interface, the Wrapper process in FastCGI generates a thread and sends the request to the script interpreter for execution. then, the original result is returned to Nginx through the original socket, and then Nginx delivers the result to the client.
Nginx uses the socket file socket to send dynamic requests to wrapper, using the Tcp protocol. Wrapper uses the CGI interface to accept requests. In this way, the web server and the interpreter can be developed independently, which avoids errors, crashes, and security problems caused by the interpreter directly calling the server interface. In addition, Nginx can focus on static page requests and forward dynamic requests, and install the script interpreter on another server, so that the pressure on the server can be apportioned.
CGI is developed as a patch for PHP programs. to install PHP, first install the library on which it depends, then, you can add options such as enable-fpm-enable-CGI when compiling configuration parameters. To compile the PHP extension module, you need to use the phpize tool in php to generate the configure file during Module compilation. if you cannot generate the configure file when running phpize, the reason is: The autoconf package is not installed.
The configuration file for the php-fpm process is/usr/local/php/etc/php-fpm.conf which can be configured accordingly for php-fpm.
Nginx configuration supports fastcgi:
Location ~ \. Php $ {
Root html;
Fastcgi_pass unix:/tmp/fastcgi. soke // establish a connection with cgi through the socket file, which is set in the php-fpm.conf
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME html $ SCRIPT_FILE_NAME; set parameters
Include fastcgi_params; // import the fastcgi parameter configuration file, which is automatically generated during nginx installation.
}