PHP + FastCGI + Nginx dynamic request processing configuration

Source: Internet
Author: User
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.

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.