Nginx reverse proxy causes large file download to fail

Source: Internet
Author: User
Tags server error log nginx reverse proxy

Nginx reverse proxy causes large file download to fail
I. symptom:
The Nginx reverse proxy is also nginx. When the client downloads a large file, the "Download failed" message is displayed when the file is downloaded to 1 GB. If the download continues in FireFox, it will download 1 GB again and then fail.
Reverse Proxy Server Error Log:

  1. 11:23:47 [error] 67663 #0: * 11 upstream prematurely closed connection while reading upstream, client :...
Agent Server Error Log:

  1. 23:33:02 [error] 5833 #101125: * 8559 upstream timed out (60: Operation timed out) while reading response header from upstream, client :....

Ii. Analysis:
1. Proxy Server Report: The upstream server closes the connection too early, as if the problem was caused by the proxy server, while the proxy server complained that the upstream server timed out. A reasonable inference is that the proxy server does not request data from the proxy server for a long time. The proxy server determines that the proxy server has dropped or completed the task, and thus actively disconnects, the proxy server finds that data is required and cannot be connected again.
2. The normal process should be: as long as the client keeps downloading, "client-> Proxy Server-> the proxy server", this series of data streams will not be interrupted, and no timeout will occur.
3. There is only one condition for Timeout: the Proxy Server caches large files.
4. the proxy server receives a download request and requests data from the proxy server. Because the network speed between the two servers is fast, the request speed of the proxy server is much higher than that of the client, this leads to the normal proxy method: the proxy server needs to cache data.
5. But the speed between the two servers is too fast. cache 1 GB of data is a matter of minutes, and the client needs to download it slowly, which may take dozens or even dozens of minutes. There is nothing to do between the proxy server and the proxy server. The silence between the two ends lasts for a long time and exceeds the timeout time (generally 60 s ), the proxy server determines that the proxy server is offline.

Iii. solution:
There are two solutions:
1. Disable cache. The client will forward the request to the proxy server every time. Add proxy_redirect default in the ngnix configuration of the proxy server;

  1. Proxy_pass http: // 192.168.0.1;
  2. Proxy_redirect default;
  3. Proxy_buffering off;

2. Increase the timeout between two servers and add the following in the configuration of the proxy server:

  1. Client_body_timeout 3600;
  2. Client_header_timeout 1800;
  3. Keepalive_timeout 15;
  4. Send_timeouts 3600;
These are actually very different. If you cannot tell the difference, set them all.





-- End --



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.