I am building a Rails 5 app that is deployed to AWS elastic beanstalk.The app is running into the error 413 (Request Entity Too Large). I have been looking around Google, Stackoverflow, and Serverfault. All of these resources point me to using client_max_body_size to increase the upload capacity of the app. There are supposedly 2 ways of doing this, both involving using .ebextensions. The first is writing a simple script with:

    content: |
      client_max_body_size 2G;

The second option is to override the nginx.conf. I have done both of the options, but I still keep getting the error 413 (Request Entity Too Large). I've tried all the configurations out there for option 1. For both options I manually reloaded nginx with:

sudo service nginx reload

This is was on my last attempt. I've been working with option 2 to override nginx.conf, so here is my own nginx.conf:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

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

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;

http {
    client_max_body_size 2G;

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

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

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

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    index   index.html index.htm;

    server {
        client_max_body_size 2G;

        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location /movies {
            client_max_body_size 2G;

        # redirect server error pages to the static page /40x.html
        error_page 404 /404.html;
            location = /40x.html {

        # redirect server error pages to the static page /50x.html
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {

        # proxy the PHP scripts to Apache listening on
        #location ~ \.php$ {
        #    proxy_pass;

        # pass the PHP scripts to FastCGI server listening on
        #location ~ \.php$ {
        #    root           html;
               #    fastcgi_pass;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht {
        #    deny  all;

# Settings for a TLS enabled server.
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        # It is *strongly* recommended to generate unique DH parameters
#        # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
#        #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#        ssl_prefer_server_ciphers on;
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#        location / {
#        }
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }


I need some help. Any help. I am lost as to what I should do next. Everything i have tried is not working at all. Help would be greatly appreciated.


To disable client_max_body_size you can change the value directive to 0. Or If you need to limit it to some extent, you can add like client_max_body_size 26m;. There is 'm' in the value that says it using megabytes, I think that's what you're missing. And if there is no 'm' mean that the limit body size is 26 bytes, I doubt you want that. Here is the documentation http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size. Hope this help. Thanks.

| improve this answer | |

Elastic Beanstalk now has native support for setting Nginx configuration: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html

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.

To increase the maximum upload size specifically, 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;

I think the method of writing a file using the files: ebextension used to work, but if you SSH onto the machine while a deploy is in progress, you can see the file is created by your configuration, and then removed by a later deployment phase.

| improve this answer | |

I have tried all .ebextensions method of adding implementation level configuration and it didn't help me in the latest Amazon Linux AMI. You need to follow this structure to increase the upload size. You need to follow this structure to increase the upload size limit.

Add the below folder setup in the root level of your project folder.

Folder structure (.platform/nginx/conf.d/proxy.conf)


Add this line to proxy.conf (Inside .platform/nginx/conf.d/ folder)

client_max_body_size 50M;

commit this file and deploy again using eb deploy.

| improve this answer | |

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.