0

If I spin up a nodejs server and use busboy then I am able to upload large files (10+ gbs) but when i use the same nodejs code and use nginx as a reverse proxy then nginx throws "413 request entity too large"

Has anyone encountered such issue? How do we solve this? I know i can set a "client_max_body_size" variable but this would mean there will still be a hard limit of the file.

My nginx config looks like the following:


server {
  listen 80;
  server_name *.example.local;

  location /api {
    proxy_pass   http://host.docker.internal:5000;
    proxy_pass_header Accept;
    proxy_pass_header Server;
    keepalive_requests 1000;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header    X-Real-IP       $remote_addr;
    proxy_set_header Host $host;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "upgrade";
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
    client_max_body_size        100M;
  }

}
Phantom007
  • 2,079
  • 4
  • 25
  • 37

3 Answers3

0

client_max_body_size size;

Sets the maximum allowed size of the client request body. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.

Source

Taxel
  • 3,859
  • 1
  • 18
  • 40
  • *Please be aware that browsers cannot correctly display this error.* What does this mean? I have seen it displayed, and it is part of the HTTP 1.1 specification. Should this say that browsers do not display a user-friendly error message? – Liam Apr 11 '23 at 21:49
  • Yes I think that's what they mean. Maybe the docs were written when browsers would not display the error like they do nowadays and browsers have caught up to the spec since then. But I haven't personally seen this error in a browser, so no idea how it looks in practice. – Taxel Apr 17 '23 at 08:51
  • I have seen it but can't reproduce it easily right now. Looking at some Google image search results, it looks like nginx returns a basic html response containing something like `

    413 Request Entity Too Large


    nginx`
    – Liam Apr 18 '23 at 16:02
0

In your nginx configuration you have client_max_body_size=100M. You need to adjust it according to your needs like 15G etc. This property of configuration defines the max size of body payload a client can send to Nginx. If payload size is greater than this, a 413 http status is sent to client. Setting it to 0 (as suggested by Taxel) will disable the payload size check but this will expose the server to outside attack where a malicious user keeps your server busy by sending random big files which can deteriorate server performance.

Eduard Hasanaj
  • 865
  • 4
  • 10
0

Answering my own question:

In order to disable request/proxy buffering in my nginx reverse proxy, I had to add the following directives in the nginx config file

proxy_buffering off; 
proxy_request_buffering off; 

So, now my nginx config file looks like the following:

server {
  listen 80;
  server_name *.example.local;

  location /api {
    proxy_pass   http://host.docker.internal:5000;
    proxy_pass_header Accept;
    proxy_pass_header Server;
    keepalive_requests 1000;
    proxy_redirect off;
    proxy_buffering off;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_set_header    X-Real-IP       $remote_addr;
    proxy_set_header Host $host;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection "upgrade";
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
    client_max_body_size        0;
    proxy_buffering             off; # <-----
    proxy_request_buffering     off; # <-----
  }

}
Phantom007
  • 2,079
  • 4
  • 25
  • 37