I'm running into "413 Request Entity Too Large" errors when posting files larger than 10MB to our API running on AWS Elastic Beanstalk.
I've done quite a bit of research and believe that I need to up the client_max_body_size for Nginx, however I cannot seem to find any documentation on how to do this using Elastic Beanstalk. My guess is that it needs to be modified using an ebetension file.
Anyone have thoughts on how I can up the limit? 10MB is pretty weak, there has to be a way to up this manually.
EDIT: After you've deployed a build with the instructions in the accepted answer by Nick Parsons, you may need to restart the nginx server to pick up the changes.
To do this, ssh to the instance and do
sudo service nginx reload
To learn more about reloading, see http://nginx.org/en/docs/beginners_guide.html.
In a previous version of Elastic Beanstalk, I was able to add a container_command to accomplish this, but now I am finding, like @cdmckay, that this causes a deployment failure. If you rebuild your environment it will pick up the client_max_body_size settings as well as long as that instruction is in your config file.
The accepted answer didn't work for me since I have a JVM-based app and it seems to do NGINX configuration differently. I would see a proxy.conf file being created during the deploy but then later deleted before the deploy was completed. AWS documentation explains how to configure the proxy:
Create an
.ebextensions/nginx/conf.d/proxy.conf
file that contains just the line:client_max_body_size 40M;
There are two methods you can take for this:
Supported/recommended in AWS documentation
For some application types, like Java SE, Go, Node.js, and maybe Ruby (it's not documented for Ruby, but all the other Nginx platforms seem to support this), Elasticbeanstalk has a built-in understanding of how to configure Nginx.
To increase the maximum upload size specifically, then create a file at
.ebextensions/nginx/conf.d/proxy.conf
setting the max body size to whatever size you would prefer:Create the Nginx config file directly
After much research and hours of working with the wonderful AWS support team, I created a config file inside of
.ebextensions
to modify the nginx config. This change allowed for a larger post body size.Inside of the
.ebextensions
directory, I created a file called01_files.config
with the following contents:This generates a proxy.conf file inside of the /etc/nginx/conf.d directory. The proxy.conf file simply contains the one liner
client_max_body_size 20M;
which does the trick.Note that for some platforms, this file will be created during the deploy, but then removed in a later deployment phase.
You can specify other directives which are outlined in Nginx documentation.
http://wiki.nginx.org/Configuration
Hope this helps others!
Alternatively you could change the proxy server to Apache. To do this, go to the Configuration and Edit the Software Configuration. The first option here is “Proxy server”, select “apache”.
The accepted answer did not work for me, so instead I overrode the nginx configuration with my own.
I created a file called
nginx.conf
under the directory.ebextensions/nginx/
I SSHed into a running instance of my Beanstalk app, and copied the contents of the
nginx.conf
file, usingcat /etc/nginx/nginx.conf
and copying from the terminal.I pasted the contents into the
nginx.conf
file I previously created in.ebextensions/nginx/
, and modified the http directive to includeclient_max_body_size 50M;
. I finally redeployed my app usingeb deploy
and it worked. You should get the following message during deployment:These are the contents of my
.ebextensions/nginx/nginx.conf
file:I did not have to restart the nginx service nor the environment.
Note: Make sure your .ebextensions is part of the .zip file created and uploaded to Beanstalk during deployment (it's not ignored in
.gitignore
or.ebignore
if you're using it).For Java Platform
To create the NGINX config proxy file you should just add
.ebextension/nginx/conf.d/proxy.conf
filewith the content
client_max_body_size 20M;
in it."proxy.conf" will be deployed to "/etc/nginx/conf.d/proxy.conf" and automatically included by the NGINX config.