In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people don't understand the knowledge points of this article "How to configure and optimize FastCGI in Nginx", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "How to configure and optimize FastCGI in Nginx".
fastcgi:
FastCGI is an evolution of CGI. The main disadvantage of the traditional cgi interface approach is poor performance because every time the http server encounters a dynamic program, it needs to restart the script parser to perform the parsing, and the results are returned to the http server. This is almost unusable when dealing with high concurrency. In addition, the traditional cgi interface is also very poor security, and is now rarely used.
fastcgi interface mode adopts c/s structure, which can separate http server and script parsing server, and start one or more script parsing daemons on script parsing server at the same time. Each 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 http servers to exclusively handle static requests or return results from dynamic scripting servers to clients, which greatly improves the performance of the entire application system.
Nginx does not support direct calls or parsing of external programs, all external programs (including php) must be called through the fastcgi interface. The fastcgi interface is a socket under linux (this socket can be a file socket or an ip socket). To invoke a cgi program, you also need a fastcgi wrapper that binds to a fixed socket, such as a port or file socket. When nginx sends a CGI request to this socket, the wrapper accepts the request through the fastcgi interface, and then derives a new thread that calls the interpreter or external program processing script and reads the returned data; then, the 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 process of nginx+fastcgi. Detailed process, as shown in the figure.
Examples:
Example of fastcgi parameter optimization configuration in nginx
After configuring nginx+fastcgi, in order to ensure the high speed and stable operation of php environment under nginx, some fastcgi optimization instructions need to be added. Here is an example of an optimization that adds the following code to the http hierarchy 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;
Meaning of the above code:
The first line of code specifies a file path, directory structure level, keyword area storage time, and inactive deletion 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 requests to fastcgi. This value is the timeout for sending requests 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 specifies how much buffer is needed to read the first part of the fastcgi response. This value indicates that the first part of the response (response header) will be read using a 64kb buffer. It can be set to the buffer size specified by the fastcgi_buffers option.
fastcgi_buffers Specifies how many and how large buffers are needed locally to buffer fastcgi reply requests. If a php script generates a page size of 256kb, four 64kb buffers will be allocated for caching; if the page size is larger than 256kb, the portion 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 on hard disk. Generally this value should be the middle of the page size generated by php scripts in the site. If most scripts in the site generate page size of 256kb, then you can set this value to "16 16k","4 64k", etc.
The default value for fastcgi_busy_buffers_size is twice fastcgi_buffers.
fastcgi_temp_file_write_size indicates how many chunks are used when writing cache files, and the default value is twice fastcgi_buffers.
fastcgi_cache means to turn on the fastcgi cache and assign it a name. Turning on cache is very useful to reduce cpu load and prevent 502 errors, but turning on cache can also cause a lot of problems, depending on the situation.
fastcgi_cache_valid and fastcgi are used to specify the cache time of response codes. The values in the example indicate that 200 and 302 responses are cached for one hour, 301 responses are cached for one day, and other responses are cached for one minute.
The above is the content of this article about "How to configure FastCGI optimization in Nginx". I believe everyone has a certain understanding. I hope the content shared by Xiaobian will be helpful to everyone. If you want to know more relevant knowledge content, please pay attention to 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: 0
*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.