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

如何解决Elastic Beanstalk中Golang服务大文件上传失败问题

Fixing "client intended to send too large body" in Elastic Beanstalk Go Apps

Hey there! Let's get that file upload limit sorted out for your Go service on Elastic Beanstalk. The error you're seeing is definitely from Nginx's default client_max_body_size setting (which is 1MB), and it looks like your config fix isn't being applied properly. Let's walk through the most common issues and fixes step by step:

1. First, Check Your ebextensions Directory Name

Elastic Beanstalk is case-sensitive here—make sure your directory is named ebextensions (all lowercase), not ebExtensions. If the name's wrong, Elastic Beanstalk won't pick up your config file at all.

2. Fix the YAML Indentation in Your Config

YAML is super picky about indentation, and your current 01_nginx.config has formatting issues that are probably causing it to be ignored. Here's the corrected version with proper indentation:

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

Make sure each nested level is indented with 2 or 4 spaces (consistency matters!).

Most modern Elastic Beanstalk environments use Amazon Linux 2, which prefers the .platform directory over ebextensions for Nginx configs. Here's how to set this up:

  • Create this directory structure at your project root: .platform/nginx/conf.d/
  • Inside that folder, make a new file (e.g., client_max_body.conf) with just this line:
    client_max_body_size 20M;
    
  • Redeploy your app—this config will automatically be loaded by Nginx without extra steps.

4. Verify the Config is Applied

Once you've fixed the config and redeployed, let's confirm it's working:

  • SSH into your Elastic Beanstalk instance with eb ssh
  • Check if your config file exists and has the right content:
    cat /etc/nginx/conf.d/proxy.conf  # For ebextensions method
    # OR
    cat /var/app/current/.platform/nginx/conf.d/client_max_body.conf  # For .platform method
    
  • Validate Nginx's config is valid:
    sudo nginx -t
    
  • If everything checks out, restart Nginx to be safe:
    sudo systemctl restart nginx
    
  • Finally, confirm the client_max_body_size is set globally:
    sudo nginx -T | grep client_max_body_size
    
    You should see your 20M value in the output.

5. Check for Overlapping Configs

If you still see the error, there might be another Nginx config overriding your setting. Run sudo nginx -T and search for client_max_body_size—if you see a smaller value (like 1MB) in a location / block or another config file, you'll need to update that specific file to match your 20M limit.

Start with the first two steps (directory name and YAML indent)—those are the most common mistakes for new Elastic Beanstalk users. Let me know if you hit any snags!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 04:13:57