CGI’s full English name is Common Gateway Interface (Public Gateway Interface), which is a bridge between Nginx and dynamic script programs. Nginx sends dynamic requests to FastCGI through the FastCGI interface. The Wrapper process in FastCGI generates a thread and hands the request to The script interpreter is executed, and then the result of the interpretation and execution is returned to Nginx through the original socket, and then Nginx hands the result to the client.
Nginx sends dynamic requests to the wrapper through the socket file socket, using the Tcp protocol. The wrapper accepts requests through the CGI interface. In this way, the web server and the interpreter can be developed completely independently, thus avoiding errors, crashes and security issues caused by the interpreter directly calling the server's interface. Moreover, Nginx can be made to concentrate on processing static page requests and forwarding dynamic requests, while the script interpreter is installed on another server, so that the pressure on the server can be shared.
CGI is developed as a patch for the PHP program. To install PHP, first install the libraries it depends on, and then add support for CGI when compiling the configuration parameters --enable-fpm --enable-cgi and other options. To compile PHP extension modules, you need to use the phpize tool in PHP to generate the configure file when the module is compiled. If the configure file cannot be generated when running phpize, the reason is: the autoconf software package is not installed.
The configuration file of the php-fpm process is /usr/local/php/etc/php-fpm.conf. You can configure php-fpm accordingly.
Nginx configuration supports fastcgi:
location ~ \.php${ root html; fastcgi_pass unix:/tmp/fastcgi.soke //通过套接字文件和cgi建立联系,该文件在php-fpm.conf中设置 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME html$SCRIPT_FILE_NAME;设置参数 include fastcgi_params; //导入fastcgi参数配置文件,该文件在nginx安装时自动生成。 }
Nginx provides web services, similar to Apache, IIS and lighthttp;
If the web service receives a PHP file request, it will transfer the request to PHP for processing and return the processing result;
FastCGI is an operating mode of PHP. In addition, it can also be run in CGI or ISAPI mode.
In addition, if you are using the windows platform, it is recommended to use Apache+PHP+Mysql, which is simpler. If it has to be related to Microsoft's IIS, it may be more troublesome, at least I think so; if you are using the Linux platform, it is recommended Using Nginx+PHP+Mysql, PHP5.3 has built-in php-fpm, which is very convenient to install and use.
Nginx can also be used on the Windows platform. If necessary, please contact us. It is currently in use and is ready-made. I now use Linux+Nginx+PHP+Mysql+Postgresql+Mongodb.
There is no need to restart the server. The settings I developed are on win2003+apache+php+fastcgi, and there is no delay in taking effect. And it should be noted that the loaded memory is not the PHP file itself, but the interpreter. Every time the PHP interpreter is opened and released, system resources will be consumed. The original multi-process has become a lightweight process, eliminating the frequent loading and unloading of the interpreter. , it just reduces the system pressure and does not conflict with PHP file updates.