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:
- 11:23:47 [error] 67663 #0: * 11 upstream prematurely closed connection while reading upstream, client :...
Agent Server Error Log:
- 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;
- Proxy_pass http: // 192.168.0.1;
- Proxy_redirect default;
- Proxy_buffering off;
2. Increase the timeout between two servers and add the following in the configuration of the proxy server:
- Client_body_timeout 3600;
- Client_header_timeout 1800;
- Keepalive_timeout 15;
- Send_timeouts 3600;
These are actually very different. If you cannot tell the difference, set them all.
-- End --