Nginx does not serve large files

nginxstatic-files

When trying to download a large file (not sure what size is enough, trying to download 5Gb), connection is stuck:

$ wget --verbose http://example.net/large.zip -O /dev/null
--2016-12-14 12:52:38--  http://example.net/large.zip
Resolving example.net (example.net)... 1.2.3.4
Connecting to example.net (example.net)|1.2.3.4|:80... connected.
HTTP request sent, awaiting response...

And this is going on forever, and by forever I mean 10 minutes at least.

nginx config for this kind of files:

location ~* ^.+\.(css|js|ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
   access_log off;
   log_not_found off;
   expires 7d;
}

Small static files (and by small I mean for example 50Mb ones) are served fine.

Turning access_log off; to "on" does not help, there is nothing in logs on this request.

Changing file type from zip to another type does not help.

The most strange thing is that if I start the download and after this restart nginx, the download starts just fine. But only this one. If you start another download after server restart, it doesn't work in the same way.

Best Answer

For me the remedy were these two settings:

In the file: /etc/nginx/nginx.conf

Add:

proxy_max_temp_file_size 0;
proxy_buffering off;

Between the lines client_max_body_size 128M; and server_names_hash_bucket_size 256;:

http {

client_max_body_size 128M;
proxy_max_temp_file_size 0;
proxy_buffering off;
server_names_hash_bucket_size 256;