Richard
Richard

Reputation: 43

Nginx truncates responses after 5 MB of data

With Nginx -v 1.10.3 (Ubuntu) I have this configuration for a virtual host:

server {
  listen 443 ssl;
  listen [::]:443 ssl;

  include snippets/ssl.conf;

  server_name  myserver.example.com;

  proxy_buffering off;
  proxy_store off;

  location / {
    include proxy_params;
    client_max_body_size 100m;
    proxy_pass http://127.0.0.1:3033;
    proxy_buffering off;
  }

}

The application being proxied is a rails app. I can upload files up to 100MB.

include snippets/ssl.conf

Contains only certificates.

include proxy_params;

Contains these directives:

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

When I connect to the backend by tunnelling the port 3033 via ssh I can download the files and they are identical.

When connecting through proxy, the file is always truncated after 5242880 bytes - i.e. 5MB regardless of the file type or original size.

The truncating is consistent. There is enough free space on the disk, enough free inodes. No error messages in the nginx logs.

When tryint to donwload a 31MB file (calibre installation ...) The access logs show this:

AAA.BBB.CCC.DDD - - [08/Nov/2018:16:36:59 +0100] "GET /rails/active_storage/disk/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaDFsVlVkdlVFaFFha1E1V2tKUk5HbG9RMVU0Vm1JNGJVY0dPZ1pGVkE9PSIsImV4cCI6IjIwMTgtMTEtMDhUMTU6NDE6NTkuMDMyWiIsInB1ciI6ImJsb2Jfa2V5In19--9ba3dd25c32c16ce10ef884b80f9f6d3705717f2/calibre-3.33.1.dmg?content_type=application%2Fx-bzip&disposition=attachment%3B+filename%3D%22calibre-3.33.1.dmg%22%3B+filename%2A%3DUTF-8%27%27calibre-3.33.1.dmg HTTP/1.1" 200 5253135 "https://myserver.example.com/supplies/2" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"

So the file size is shown already truncated.

I have done my homework and looked through the nginx documentation as well as searched but all other users reported errors in error logs, random truncating or truncating only certain filetypes.

Any help is greatly appreciated.

Upvotes: 3

Views: 3706

Answers (1)

jbheren
jbheren

Reputation: 506

I just got an anwer from @amiuhle that worked on my case :

Use proxy_http_version 1.1;

By default, nginx uses HTTP 1.0 for proxying, which does not support chunked transfer encoding.

http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version

Upvotes: 4

Related Questions