About Me

My photo
Senior Java Engineer, Wavecell Pte Ltd. Singapore

Thursday, August 17, 2017

Changing max pass through request body size in Nginx for AWS Elastic Beanstalk

Most of the NodeJS applications in Elastic Beanstalk uses a Nginx as reverse proxy which routes requests from port 80 to 8080. Reason being the out of the box NginX support for NodeJS applications in beanstalk.

Recently i was working in a nodejs application which uploads images and video files to AWS S3 and our deployment environment is Elastic Beanstalk.

With the default Nginx configuration i came across following error when i try to upload large files.

-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2017/08/17 08:12:16 [error] 20884#0: 
*526 client intended to send too large body: 41324010 bytes,
client: 10.0.0.10, 
server: , request: "POST /filelink/upload HTTP/1.1", 
host: "fileuploader***.elasticbeanstalk.com"
-------------------------------------

As clearly mentioned in the log Nginx doesn't allow requests with large body to pass through it. Default max value is ~2MB. 

Elastic beanstalk allows this kind of configurations to be manipulated via, .ebextensions. What we need to do is to create a folder as .ebextensions in your root directory of the node project and add a SOME_NAME.config file to it with the following Nginx configuration. Here we are changing the property, client_max_body_size to 50M which increases the pass through file size.

files:
  /etc/nginx/conf.d/proxy.conf:
    content:  |
      client_max_body_size 50M;

Here is a sample nginx configuration from official documentation.


Let me know your thoughts.

No comments:

Post a Comment


Handling POST request using akka-http in a akka-actor system

Akka-htp is a well known module for providing full server side as well as client side http stack currently supporting Scala and Java langua...