Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

413 Request Entity Too Large - Elastic Beanstalk + Load Balancer + Node.js application

I have looked on all possible stackoverflow posts and have tried all the different aproaches. None worked. There seems also no official documentation on this. Everything works fine in my local app, and I can upload images of any size, but as soon as its deployed in my elastic beanstalk, I seem to have a limit of 1M per image upoad.

The Problem: Every time a user posts an image that is larger than 1MB, I receive the 413 error message with nginx.

Elastic Beanstalk Log: 2020/07/28 17:22:53 [error] 10404#0: *62 client intended to send too large body: 2800500 bytes, client: 172.31.18.162, server: , request: "POST /comment/image_post/11003031 HTTP/1.1", host: "myapp.com", referrer: "https://myapp.com/11003031"

What I did to try to solve the problem:

I created a .ebextensions folder in my node,js application root folder, added the below code and called it proxi.config, and pushed it to my github which deploys to Elastic Beanstalk via pipeline. I can see the proxi.config in my repository but for some reason it is automatically overwritten by the load balancer (I guess from what I have been reading).

    proxi.config
container_commands:
  01_reload_nginx:
    command: "service nginx reload"
files:
    "/etc/nginx/conf.d/proxy.conf":
      mode: "000755"
      owner: root
      group: root
      content: |
        client_max_body_size 25M;

If this is complicated to solve, is there no other way to increase the 1M limit?

like image 790
Rarcifa Rarcifa Avatar asked Jul 28 '20 18:07

Rarcifa Rarcifa


1 Answers

The probable reason why your proxy.conf is not being used is because you are using current version of EB, which runs on Amazon Linux 2 (AL2). However, the proxy settings you are trying to use are for old version of EB running on AL1.

For AL2, the nginx settings should be placed in .platform folder, not in .ebextenations as shown in the docs.

Thus you can try the following:

File .platform/nginx/conf.d/myconfig.conf with the content of

client_max_body_size 25M;

Please note that I can't verify the nginx setting it self. It still may not work as it may be wrong setting or have wrong form. But the use of .ebextenations instead of .platform is definitely an issue on AL2 EB environments.

like image 149
Marcin Avatar answered Nov 01 '22 14:11

Marcin