'Aws elastic beanstalk nginx config is not working for my nodejs web application

I am using amazon elastic beanstalk for my nodejs website with nginx as proxy. I want to set the maximum upload size to 20mb as the default size is 1mb. I have tried all possible ways of setting up client_max_body_size in .ebextensions/.config file. But none seem to be working as i still get the 413 error. Below is my config file


container_commands:
  01_reload_nginx:
    command: "sudo service nginx reload"

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


Solution 1:[1]

The /etc/nginx/conf.d/proxy.conf is for Amazon Linux 1 (AL1). However, you may be using current version of EB (not specified in the question), which is Amazon Linux 2 (AL2).

For AL2, you should use the config files in .platform/nginx/conf.d/.

There are many differences between AL1 and AL2 in EB:

Thus you may need to modify extra files to make your application work if you are migrating it from AL1 to AL2.

Solution 2:[2]

For Elastic Beanstalk - Amazon Linux 2:

Create .platform/nginx/conf.d/client_max_body_size.conf in the application root folder.

Add one line to the file: client_max_body_size 20M;

Deploy your code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Marcin
Solution 2 Sharhabeel Hamdan