You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nginx与Amazon ElasticBeanstalk中413请求实体过大问题未解决

Fixing 413 Request Entity Too Large on Amazon Elastic Beanstalk (Amazon Linux 2018.03 + Ruby/Puma)

I’ve run into the exact same issue with older AL1-based EB environments—your initial config makes total sense, but Elastic Beanstalk’s default Nginx setup often overrides custom proxy.conf files without you noticing. Here’s how to get it working:

Why Your Initial Config Failed

Amazon Linux 2018.03 EB environments load Nginx configurations in this order:

  1. /etc/nginx/conf.d/*.conf (your original proxy.conf lives here)
  2. /etc/nginx/conf.d/elasticbeanstalk/*.conf (EB’s auto-generated configs, including 00_application.conf)

EB’s own configs typically include a small default client_max_body_size (like 1M) that loads after your proxy.conf, overwriting your 50M setting entirely.

Solution 1: Use a High-Priority Config File

Create a config file with a name that loads after EB’s default files (using a 99_ prefix ensures this). Add this to a .ebextensions/nginx_max_upload.config file in your Rails project root:

files:
  "/etc/nginx/conf.d/99_my_proxy.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      client_max_body_size 50M;

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

The late-loading prefix guarantees your setting takes precedence over any earlier defaults.

Solution 2: Modify EB’s Auto-Generated Config

If you prefer to edit EB’s own config directly, use container_commands to inject your setting into 00_application.conf:

container_commands:
  01_add_max_body_size:
    command: 'echo "client_max_body_size 50M;" >> /etc/nginx/conf.d/elasticbeanstalk/00_application.conf'
  02_restart_nginx:
    command: "service nginx restart"

If EB already has a client_max_body_size line in that file, replace it with sed instead:

container_commands:
  01_replace_max_body_size:
    command: 'sed -i "s/client_max_body_size [0-9]*M;/client_max_body_size 50M;/" /etc/nginx/conf.d/elasticbeanstalk/00_application.conf'
  02_restart_nginx:
    command: "service nginx restart"

Don’t Forget Rails’ Own Upload Limit

Even if Nginx is fixed, Rails has its own default upload cap. Update config/application.rb to match your new Nginx setting:

config.action_dispatch.max_upload_size = 50.megabytes

Verify the Fix

After deploying, SSH into your EB instance and run this command to confirm your setting is active:

nginx -T

Search for client_max_body_size in the output—you should see your 50M value listed as the final active configuration.

内容的提问来源于stack exchange,提问作者antpaw

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:49:28