skip to Main Content

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;
  }

}

3

Answers


  1. Chosen as BEST ANSWER

    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; # <-----
      }
    
    }
    

  2. 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

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search