I have a Node.Js application deployed to Amazon Elastic Beanstalk. When uploading a file, I get the following error:

2019/03/04 17:00:42 [error] 4325#0: *722 client intended to send too large body: 30877841 bytes,
client: my ip,
server: ,
request: "POST /api/files/upload HTTP/1.1",
host: "mydomain.com",
referrer: "mydomain.com/..."

Therefore, I need to add client_max_body_size XXM to nginx.conf.


(1) But as I am using Amazon Elastic Beanstalk, I don't know how to do this, without connecting to every single EC2 instance and updating the file manually.

(2) I also want to increase the max size only for one url.


You can customize the software on a Linux Elastic Beanstalk instance using environment configuration files. For your specific case, in your local application home folder, you should have a .ebextensions directory. In that folder create a new file, let's call it "nginx.config", and place the following into that file:

    content: "client_max_body_size 10m;"
    group: root
    mode: "000644"
    owner: root

This instructs Elastic Beanstalk to create a file in /etc/nginx/conf.d/ called 00_client_max_body_size.conf, and to place a single line in this file containing:

client_max_body_size 10m;

Bundle up your application and upload a new version to Elastic Beanstalk. Once you have done this, you will notice the following on your Linux instance:

$ ls -al     /etc/nginx/conf.d
total 20
drwxr-xr-x 2 root root 4096 Mar  8 00:34 .
drwxr-xr-x 4 root root 4096 Feb 15 22:24 ..
-rw-r--r-- 1 root root   25 Mar  8 00:34 00_client_max_body_size.conf
-rw-r--r-- 1 root root 1351 Mar  8 00:35 00_elastic_beanstalk_proxy.conf
-rw-r--r-- 1 root root  283 Dec 13 00:21 virtual.conf

This will get included by the main nginx.conf file that is present on all nodejs elastic beanstalk environments, as this file has a line at the end of its http block as follows:

http {


include /etc/nginx/conf.d/*.conf;
# End Modification

I had a similar situation with a Docker deployment into Elastic Beanstalk. I was able to solve it with an added config file here: <app>/.ebextensions/increase_upload_size.config with the following code:

    command: "sudo service nginx reload"

  "/etc/nginx/conf.d/proxy.conf" :
    mode: "000644"
    owner: root
    group: root
    content: |
      client_max_body_size 20M;

The change was implemented when I did an "Upload and Deploy" within EB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.