truncated output for large files through proxy

James Lee lista at oxdrove.co.uk
Fri Jun 14 11:05:10 UTC 2013


Hello,

nginx 1.4.1 is truncating proxy output for large files.


*** Steps to reproduce ***

nginx.conf:

     location ^~ /download/ {
         proxy_pass        http://localhost:9000;
         proxy_set_header  Host $host;
     }

The back end is a very simple servlet that copies a static file to the 
output stream.  The test file is 7147652 bytes.  Small files are 
delivered correctly,


*** Test results ***

First to show that the back end is sending a full file access it 
directly on port 9000:

$ curl http://domain.local:9000/download/file.pdf | wc
   % Total    % Received % Xferd  Average Speed   Time    Time Time  Current
                                  Dload  Upload   Total   Spent Left  Speed
100 6980k    0 6980k    0     0  39.3M      0 --:--:-- --:--:-- --:--:-- 
39.6M
    39699  166238 7147652

7147652 bytes delivered correctly.


Example of failure, request via nginx:

$ curl http://domain.local/download/file.pdf | wc
   % Total    % Received % Xferd  Average Speed   Time    Time Time  Current
                                  Dload  Upload   Total   Spent Left  Speed
100  167k    0  167k    0     0  5779k      0 --:--:-- --:--:-- --:--:-- 
5992k
     1959    3853  171828

Only 171828 bytes delivered.



By restricting the download speed more bytes are delivered, slower is 
better, eg:

$ curl --limit-rate 200k http://domain.local/download/file.pdf | wc
   % Total    % Received % Xferd  Average Speed   Time    Time Time  Current
                                  Dload  Upload   Total   Spent Left  Speed
100 6980k    0 6980k    0     0   200k      0 --:--:--  0:00:34 --:--:-- 
  200k
    39699  166238 7147652



*** Workaround ***

Add limit-rate to nginx.conf:

     location ^~ /download/ {
         proxy_pass        http://localhost:9000;
         proxy_set_header  Host $host;
         limit_rate        1000k;
     }

$ curl http://domain.local/download/file.pdf | wc
   % Total    % Received % Xferd  Average Speed   Time    Time Time  Current
                                  Dload  Upload   Total   Spent Left  Speed
100 6980k    0 6980k    0     0  1000k      0 --:--:--  0:00:06 --:--:-- 
1001k
    39699  166238 7147652

Full 7147652bytes delivered


*** Other information ***

This is similar to:
http://mailman.nginx.org/pipermail/nginx/2012-April/033272.html
The workaround for this was also set a limit rate in nginx.conf.


nginx 1.4.1
Solaris 10u11




James.



More information about the nginx mailing list