By Nick Parsons

2013-09-20 03:37:03 8 Comments

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.


@user3217794 2014-05-10 23:25:18

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

Modified the above answer for the sake of security (and the syntax was wrong, see, two 'owner:' entries in the YAML), guys, please don't set 777 permissions on ANYTHING. Unless you enjoy being hacked, and set the owner of Nginx config files to root.

Also see the below answer to make nginx pickup this change after deployment.

@Nick Parsons 2013-09-23 04:19:49

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 extend Elastic Beanstalk's default nginx configuration, add .conf configuration files to a folder named .ebextensions/nginx/conf.d/ in your application source bundle. Elastic Beanstalk's nginx configuration includes .conf files in this folder automatically.

|-- .ebextensions
|   `-- nginx
|       `-- conf.d
|           `-- myconf.conf
`-- web.jar

Configuring the Reverse Proxy - Java SE

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:

client_max_body_size 50M;

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 called 01_files.config with the following contents:

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

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.

Hope this helps others!

@tim peterson 2013-09-27 23:38:29

yes very helpful, glad you were able to fix your problem!

@h-kippo 2014-12-11 09:12:22

The file format is documented at…. The progress is logged at /var/log/cfn-init.log. In the logs you should see something like 2014-xx-xx xx:xx:xx,xxx [DEBUG] Writing content to /etc/nginx/conf.d/proxy.conf. I'm not sure, but it seemed like restarting the server might be necessary.

@Israel Barba 2015-01-16 22:43:18

No working with me. I have puma.

@Dennis 2016-01-17 21:37:29

Working for me with puma. Had to restart service like @Will said though (sudo service nginx reload).

@alexs 2017-06-04 21:35:43

Hopefully this might help someone else as it took me a while... indentation is important - it has to conform the the YAML spec -

@GabLeRoux 2018-03-29 17:54:46

Confirmed working, make sure .ebextensions is not in .ebignore and .gitignore 🖖 I did not need to restart nginx service, eb deploy and it worked 🎉

@Daniel Compton 2018-05-24 02:44:51

Note that for Java/Go/maybe other applications, you can just create the file at .ebextensions/nginx/conf.d/proxy.conf. If you try to use this method on those apps, the configuration file is created, but then later replaced during the deployment phase.

@psabbate 2018-08-10 14:23:55

This is not working for me, I created a post…

@Kapil 2018-08-17 14:30:24

For node js, the second method (files: ) worked for me. The first one did not work. Even AWS support advised to use the second method for node js…

@fagiani 2018-08-20 18:58:39

This is a great solution but looks like at this time it wont't work for other stacks like Ruby. Just tested it now.

@Raymond26 2015-12-09 20:48:07

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;

@Udo G 2017-03-07 08:03:38

Unfortunately, that didn't work for me (single-container Docker ELB) - not even after a reboot of the instance. Logging in to the instance via SSH there is no proxy.conf file being created in /etc/nginx/conf.d/

@Raymond26 2017-03-08 08:24:47

I'm assuming it's because of the fact you're using a Docker ELB and it does nginx conf differently. My answer is for Java-preset ELB.

@Dimitar Vukman 2017-12-29 14:25:20

I am using elb and java app. Works for me! Thanks!

@Lyudmyla 2018-04-24 10:30:07

For Java Platform

To create the NGINX config proxy file you should just add

.ebextension/nginx/conf.d/proxy.conf file

with 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.

@kskyriacou 2017-08-31 08:07:23

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, using cat /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 include client_max_body_size 50M;. I finally redeployed my app using eb deploy and it worked. You should get the following message during deployment:

INFO: Nginx configuration detected in the '.ebextensions/nginx' directory. AWS Elastic Beanstalk will no longer manage the Nginx configuration for this environment.

These are the contents of my .ebextensions/nginx/nginx.conf file:

# Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/;
worker_processes        auto;
worker_rlimit_nofile    33193;

events {
    worker_connections  1024;

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";

    server {
        listen        80 default_server;
        access_log    /var/log/nginx/access.log main;

        client_header_timeout 60;
        client_body_timeout   60;
        keepalive_timeout     60;
        gzip                  off;
        gzip_comp_level       4;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;

    client_max_body_size 50M;

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).

@Icid 2018-03-29 14:16:43

Thanks for this! I was wondering which platform you were using though? For some reason Beanstalk isn't detecting my ` .ebextensions/nginx/nginx.conf` file even though it's in the zip file and git repo.

@GabLeRoux 2018-03-29 17:50:08

Upvoted for the note. I was ignoring the .ebextensions which caused the accepted and popular answer to fail. I did not try everything else you mentionned, but thanks for the note 🍻

@pascal 2017-03-24 05:34:35

For Golang without Docker I followed these instructions from aws doc:

Configuring the Reverse Proxy

If you want to include directives in addition to those in the nginx.conf http block, you can also provide additional configuration files in the .ebextensions/nginx/conf.d/ directory of your source bundle. All files in this directory must have the .conf extension.

I created the file proxy.conf in .ebextensions/nginx/conf.d/ at the root of my project, with simply 1 line inside:

client_max_body_size 20M;

If it still doesn't work, make sure .ebextensions folder and sub-folders are included in your deployment zip. No need to restart Nginx manually.

@ConorB 2016-10-03 10:47:11

Following on from the accepted answer, you need may need to reload the nginx config file.

In order to do this add the following command

        command: "service nginx reload"

This would be better practice than ssh'ing into your eb instance and manually doing it with a command.

This combined with the accepted answer solved the same issue for me. (Rails, Puma, NGINX)

@David Smits 2016-05-30 10:28:01

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”.

@Tom Harvey 2018-10-31 09:27:45

Apache has it's own LimitRequestBody directive to set the max size of uploaded files.

@Will 2015-02-04 04:15:10

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

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.

@cdmckay 2015-04-27 23:05:23

Is this necessary? If you don't add this, how will it restart?

@Will 2015-04-29 05:06:15

In my experience I found this necessary.

@cdmckay 2015-04-30 16:38:05

The reload command was causing my instance issues

@Will 2015-05-17 22:14:09

@cdmckay can you say more about the instance issues the reload command caused?

@cdmckay 2015-05-18 19:38:19

I didn't look into it too closely, but it basically prevented my server from launching until I removed it. It doesn't appear to be necessary.

@alexs 2017-06-17 10:36:56

in my experience i found this was necessary however, I had to add a check to see if nginx was running before trying to restart it for new instances - 'pgrep nginx && service nginx reload || true'

@Tom Harvey 2018-10-31 09:28:33

The answer from @ConorB better describes how to restart nginx after this config is in place.

Related Questions

Sponsored Content

12 Answered Questions

[SOLVED] SSH to Elastic Beanstalk instance

2 Answered Questions

2 Answered Questions

11 Answered Questions

[SOLVED] Node.js + Nginx - What now?

  • 2011-02-15 20:49:02
  • Van Coding
  • 318439 View
  • 898 Score
  • 11 Answer
  • Tags:   node.js nginx concept

0 Answered Questions

How can I increase the client_max_body_size in Elastic Beanstalk

3 Answered Questions

1 Answered Questions

unable to increase client_max_body_size

3 Answered Questions

[SOLVED] nginx upload client_max_body_size issue

1 Answered Questions

1 Answered Questions

[SOLVED] Basic Auth on Nginx server on Elastic Beanstalk

Sponsored Content