In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "the setting method of buffer parameters in Nginx". In the daily operation, I believe that many people have doubts about the setting method of buffer parameters in Nginx. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "setting methods of buffer parameters in Nginx". Next, please follow the editor to study!
Open the error.log log file of Nginx and find a lot of warn warning errors, prompting:
① 2016-03-25 13:18:35 [warn] 1171: 0: * 10875 an upstream response is buffered to a temporary file / var/cache/nginx/fastcgi_temp/0/08/0000000080 while reading upstream, client: 106.38.241.105, server: blog.tanteng.me, request: "GET / page/38/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "blog.tanteng.me".
As shown in the figure:
And a warning like this:
② 2016-03-25 15:16:07 [warn] 6172: 0: * 1243 a client request body is buffered to a temporary file / var/cache/nginx/client_temp/0000000001, client: 193.201.227.83, server: blog.tanteng.me, request: "POST / xmlrpc.php HTTP/1.1", host: "blog.tanteng.me", referrer: "http://tantengvip.com/xmlrpc.php"
This requires setting to increase the size of the client_body_buffer_size. If the buffer setting is small, Nginx will write the contents to the hard disk, which will affect performance. So add the following fastcgi buffers parameter settings to nginx.conf:
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
Location ~\ .php$ {
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
Fastcgi_connect_timeout 60
Fastcgi_send_timeout 180
Fastcgi_read_timeout 180
Fastcgi_buffer_size 128k
Fastcgi_buffers 256 16k
Client_body_buffer_size 1024k
Include fastcgi_params
}
After setting up, no such error log was found for a period of time.
Buffer Mechanism of Nginx
The Response,Nginx from FastCGI Server is buffered in memory and then sent to the client browser in turn. The size of the buffer is controlled by two values, fastcgi_buffers and fastcgi_buffer_size.
For example, the configuration is as follows:
one
two
Fastcgi_buffers 8 4K
Fastcgi_buffer_size 4K
Astcgi_buffers controls nginx to create up to eight buffers with a size of 4K, while fastcgi_buffer_size is the size of the first buffer when processing Response and is not included in the former. So the total maximum memory buffer size that can be created is 8*4K+4K = 36k. These buffers are generated dynamically based on the actual Response size and are not created at once. For example, for an 8K page, Nginx will create a total of 2 buffers of 2K4K.
When Response is less than or equal to 36k, of course all data is processed in memory. What if Response is greater than 36k? That's what fastcgi_temp is for. The extra data will be temporarily written to the file and placed under this directory.
Buffer Size optimization
The size of buffer is the most important parameter you need to tune. If the buffer size is too small, it will cause nginx to use temporary files to store response, which will cause disk to read and write IO. The greater the traffic, the more obvious the problem.
Client_body_buffer_size handles the buffer size of the client request body. Used to process POST submission data, upload files, etc. The client_body_buffer_size needs to be large enough to accommodate if you need to upload POST data.
Fastcgi_buffers,proxy_buffers handles the back-end response. If the buffer is not large enough, it will also cause the disks to be IO. It is important to note that they have an upper limit, which is controlled by fastcgi_max_temp_file_size and proxy_max_temp_file_size.
FastCGI buffer setting main parameters fastcgi_buffers 4 64k
This parameter specifies how many and how many buffers will be used to read the reply from the FastCGI process locally. Assuming that the page size generated by a PHP or JAVA script is 256kb, it will be allocated 4 64kb buffers to cache. If the page is larger than 256kb, then the part larger than 256kb will be cached to the path specified by fastcgi_temp, this is not a good way, memory data processing is faster than the hard disk, generally this value should be the site PHP or JAVA script generated by the page size intermediate value, if the site most scripts generated by the page size for 256kb, then you can set the value to 1616kMag464k and so on.
Fastcgi_buffer_size=64k
How much buffer is needed to read the first part of the fastcgi reply, which indicates that the first part of the reply (response header) is read using a buffer of 1 64kb, which can be set to the fastcgi_buffers option buffer size.
Fastcgi_connect_timeout=300
Timeout for connecting to the backend fastcgi (in seconds), same as below.
Fastcgi_send_timeout=300
Request timeout to fastcgi (this specifies the timeout for sending the request to fastcgi after two handshakes have been completed)
Fastcgi_reAd_timeout=300
The timeout for receiving the fastcgi reply is also after 2 handshakes.
At this point, the study of "the setting method of buffer parameters in Nginx" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.