nginx generally sends requests to the fastcgi management process to process, taking php site as an example, php-fpm is an implementation of the Fastcgi protocol, a hypervisor that manages php-cgi. Here's the flow chart:
CGI stands for "Common Gateway Interface", a tool for HTTP servers to "talk" to programs on your or other machines, and their programs must run on a web server.
Disadvantages of CGI: When every request enters, CGI will fork a new process, and then take PHP as an example, each request consumes a considerable amount of memory, so that when it is launched, it will be completely GG.
To solve this problem, fastCgi was created.
FastCGI is like a long-live CGI, it can be executed all the time, as long as it is activated, it does not take time to fork every time (this is the most criticized fork-and-execute mode of CGI). It also supports distributed computing, meaning that FastCGI programs can be executed on hosts other than the web server and accept requests from other web servers.
Test
Create a new php file under the D:\dev_tools\nginx-1.20.0\html\php directory to prevent nginx from reporting a 404 error when the file cannot be found, as follows:
nginx fastcgi_pass is configured as follows:
The data transmitted by nginx fastcgi_pass needs to be parsed according to the FastCGI protocolIf you are interested, you can go to find out, I use sokit here to enable a TCP listening for simple reception, try to use a browser to access:http://127.0.0.1:22229/itsvse.php, as shown in the figure below:
22:06:07 DAT ---> [TCP] 127.0.0.1:1032 <1136> ..................... B.... QUERY_STRING.. REQUEST_METHODGET.. CONTENT_TYPE.. CONTENT_LENGTH.. SCRIPT_NAME/itsvse.php.. REQUEST_URI/itsvse.php.. DOCUMENT_URI/itsvse.php." DOCUMENT_ROOTD:/dev_tools/nginx-1.20.0/html/php.. SERVER_PROTOCOLHTTP/1.1..REQUEST_SCHEMEhttp.. GATEWAY_INTERFACECGI/1.1..SERVER_SOFTWAREnginx/1.20.0..REMOTE_ADDR127.0.0.1.. REMOTE_PORT1025.. SERVER_ADDR127.0.0.1.. SERVER_PORT22229.. SERVER_NAME.. REDIRECT_STATUS200.. HTTP_HOST127.0.0.1:22229..HTTP_CONNECTIONkeep-alive.. HTTP_CACHE_CONTROLmax-age=0.@HTTP_SEC_CH_UA"Chromium"; v="92", " Not A; Brand"; v="99", "Google Chrome"; v="92".. HTTP_SEC_CH_UA_MOBILE?0..HTTP_UPGRADE_INSECURE_REQUESTS1.sHTTP_USER_AGENTMozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36.....HTTP_ACCEPTtext/html,application/xhtml+xml,application/xml; q=0.9,image/avif,image/webp,image/apng,*/*; q=0.8,application/signed-exchange; v=b3; q=0.9..HTTP_SEC_FETCH_SITEnone.. HTTP_SEC_FETCH_MODEnavigate.. HTTP_SEC_FETCH_USER?1..HTTP_SEC_FETCH_DESTdocument.. HTTP_ACCEPT_ENCODINGgzip, deflate, br.. HTTP_ACCEPT_LANGUAGEzh-CN,zh; q=0.9,en; q=0.8...................... (End)
|