[Switch] nginx + FastCGI File Download is incomplete

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.