AWS Elastic Beanstalk, Rails, Carrierwave-413 Request Object Too Large

I have a Rails / Postgres application hosted on AWAS Elastic Beanstalk. One form of sending data to my application also allows users to select multiple photos in which photos are directly uploaded to Amazon S3 using Carrierwave in the same request. Although it works during the development process, it generates the "413 Request Entity Is Too Large" error.

I tried to customize my application with some suggestions for relevant posts to increase the maximum request body size, but nothing works. Not sure if I should use container commands at all. I don’t know what this does.

.ebextensions/01_files.config

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

files:
  "/etc/nginx/conf.d/proxy.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
        http {
          client_max_body_size 20M;
        }
+4
3

, , , ,

client_max_body_size 20M;

nginx.conf nginx.

nginx.conf , . , http.

nginx.conf:

upstream myapp {
  server unix:///var/run/myapp.sock;
}

  client_max_body_size 20M;

        server {
          listen 80;
          server_name mayapp.com;

          # path for static files
          root /usr/src/app/public;

          location / {
              try_files $uri @proxy;
              client_max_body_size 20M;
          }

          location @proxy {
              proxy_pass  http://myapp;
              proxy_set_header Host      $host;
              proxy_set_header X-Real-IP $remote_addr;
              client_max_body_size 20M;
          }

          client_max_body_size 20M;
        }
0

- proxy.conf .

client_max_body_size 20M;

proxy.conf .

http {
      client_max_body_size 20M;
    }

413 /, , nginx , , .

"http" directive is not allowed here in /etc/nginx/conf.d/proxy.conf:1

, 413s... /etc/nginx/conf.d , webapp.conf - ebextension. , , beanstalk . !

( ), , .

.ebextensions/01_files.config
files:
  "/etc/nginx/conf.d/webapp.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
   upstream my_app {
      server unix:///var/run/puma/my_app.sock;
    }

    server {
      listen 80;
      server_name _ localhost; # need to listen to localhost for worker tier

      location / {
        proxy_pass http://my_app; # match the name of upstream directive which is defined above
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }

      location /assets {
        alias /var/app/current/public/assets;
        gzip_static on;
        gzip on;
        expires max;
        add_header Cache-Control public;
      }

      location /public {
        alias /var/app/current/public;
        gzip_static on;
        gzip on;
        expires max;
        add_header Cache-Control public;
      }

     client_max_body_size 100M;
    }
0

, nginx .

0

Source: https://habr.com/ru/post/1614521/


All Articles