In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you the method of FastCGI configuration optimization in Nginx, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
FastCGI:
FastCGI is developed and improved from CGI. The main disadvantage of the traditional CGI interface is poor performance, because every time the HTTP server encounters a dynamic program, it needs to restart the script parser to perform parsing, and the result is returned to the HTTP server. This is almost unavailable when dealing with highly concurrent access. In addition, the security of the traditional CGI interface is also very poor, and now it is rarely used.
The FastCGI interface adopts Cramp S structure, which can separate the HTTP server from the script parsing server, and start one or more script parsing daemons on the script parsing server. Every time the HTTP server encounters a dynamic program, it can deliver it directly to the FastCGI process for execution, and then return the results to the browser. This approach allows the HTTP server to handle static requests exclusively or return the results of the dynamic script server to the client, which greatly improves the performance of the entire application system.
Nginx does not support direct calls or parsing of external programs, and all external programs (including PHP) must be called through the FastCGI interface. The FastCGI interface is socket under Linux (this socket can be either a file socket or an ip socket). In order to invoke the CGI program, you also need a wrapper of FastCGI (wrapper can be understood as the program used to start another program), and this wrapper is bound to a fixed socket, such as a port or a file socket. When Nginx sends the CGI request to the socket, through the FastCGI interface, wrapper accepts the request, and then derives a new thread, which calls the interpreter or external program to process the script and reads the returned data; then, wrapper passes the returned data to Nginx; along the fixed socket through the FastCGI interface. Finally, Nginx sends the returned data to the client, which is the whole operation of Nginx+FastCGI. The detailed process is shown in the figure.
Example:
An example of optimal configuration of FastCGI parameters in Nginx
After the configuration of Nginx+FastCGI, in order to ensure the high-speed and stable operation of the PHP environment under Nginx, some FastCGI optimization instructions need to be added. An optimization example is given below to add the following code to the HTTP level in the Nginx main configuration file.
Fastcgi_cache_path / usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_cache TEST; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m
The meaning of the above code:
The first line of code specifies a file path, directory structure level, keyword area storage time, and inactive delete time for the FastCGI cache.
Fastcgi_connect_timeout specifies the timeout for connecting to the backend FastCGI.
Fastcgi_send_timeout specifies the timeout for sending the request to FastCGI, which is the timeout for sending the request to FastCGI after two handshakes have been completed.
Fastcgi_read_timeout specifies the timeout for receiving FastCGI replies, which is the timeout for receiving FastCGI replies after two handshakes have been completed.
Fastcgi_buffer_size is used to specify the size of the buffer needed to read the first part of the FastCGI reply. This value indicates that the first part of the reply (the response header) will be read using a buffer of 1 64KB, which can be set to the buffer size specified by the fastcgi_buffers option.
Fastcgi_buffers specifies how many and how many buffers are needed locally to buffer FastCGI reply requests. If a PHP script produces a page size of 256KB, it will be allocated 4 64KB buffers to cache; if the page size is larger than 256KB, then the part larger than 256KB will be cached in the path specified by fastcgi_temp, but this is not a good method, because the data processing speed in memory is faster than that of the hard disk. Generally, this value should be the middle value of the page size generated by the PHP script in the site. If the page size generated by most of the scripts in the site is 256KB, then you can set this value to "1616k", "464k", and so on.
The default value of fastcgi_busy_buffers_size is twice that of fastcgi_buffers.
Fastcgi_temp_file_write_size indicates the size of the data block used when writing to the cache file, and the default value is twice as large as fastcgi_buffers.
Fastcgi_cache means to turn on the FastCGI cache and give it a name. Turning on caching is very useful, it can effectively reduce the load of CPU and prevent 502 errors, but turning on caching can also cause a lot of problems, depending on the situation.
Fastcgi_cache_valid and fastcgi are used to specify the caching time of the response code. The values in the example indicate that 200,302 responses will be cached for one hour, 301 responses will be cached for 1 day, and other responses will be cached for 1 minute.
These are all the contents of this article entitled "methods of FastCGI configuration Optimization in Nginx". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 284
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.