Today, I found that files on the server are not completely downloaded. I used to think it was caused by network instability. Later I found it was not. Is the reason for NG configuration.
Let's briefly talk about the buffer mechanism of nginx. For the response from the FastCGI server, nginx caches it into the memory and sends it to the client browser in sequence. The buffer size is controlled by the fastcgi_buffers and fastcgi_buffer_size values.
For example, the following Configuration:
fastcgi_buffers 8 4K; fastcgi_buffer_size 4K;
Fastcgi_buffers controls nginx to create a maximum of eight 4 K buffers, while fastcgi_buffer_size is the size of the first buffer when handling response, not included in the former. Therefore, the maximum memory buffer size that can be created in total is 8*4 K + 4 k = 36 K. These buffers are dynamically generated based on the actual response size and are not created at one time. For example, for an 8 K page, nginx creates 2*4 K buffers in total.
When the response is smaller than or equal to 36 KB, all data is processed in the memory. What if response is greater than 36 K? The role of fastcgi_temp lies in this. The extra data will be temporarily written to the file and placed under this directory.
In this case, if the permission of fastcgi_temp is incorrect, Ng users cannot access this temp directory. In this case, only part of the directory will be downloaded. The size of the generated page reaches 100 + kb, and the memory is buffered by 36 KB. The rest will be written into the file. The actual situation is that the user running nginx process does not have the write permission for the fastcgi_temp directory, so the remaining data is lost.
Solution: Set the directory permission of fastcgi_temp to the read/write permission of the nginx process user.
[Switch] nginx + FastCGI File Download is incomplete