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

Elastic Beanstalk上传超57MB文件报405错误,本地正常

Hey there, let's tackle this 405 Method Not Allowed issue you're hitting with large file uploads on Elastic Beanstalk. I've run into similar quirks with EB and Nginx before, so here are targeted areas to investigate and fix:

1. Verify Nginx Configuration is Applied Properly in EB

Elastic Beanstalk often uses layered Nginx configs, so modifying the main nginx.conf might not be enough—your setting could get overwritten by application-specific configs.

  • Fix: Create a custom Nginx config via .ebextensions to ensure the setting sticks. Make a file at .ebextensions/nginx/conf.d/large_uploads.conf with this content:
    client_max_body_size 5000M;
    
    EB will automatically load this config during deployment, avoiding conflicts with default settings.
  • Check Logs: SSH into your EB instance and check /var/log/nginx/error.log for clues. Look for entries like request body is too large—this would confirm Nginx is still blocking large requests, even if you thought you updated the setting.
2. Adjust Elastic Load Balancer (ALB) Limits

If your EB environment uses an Application Load Balancer (ALB), it has a default maximum request body size of 1MB—this is a common hidden limit that trips up large uploads.

  • Console Fix: Go to your EB environment in the AWS Console → Configuration → Load Balancer → Edit the listener. Set the "Maximum request body size" to 5000MB (or larger).
  • Code Fix: Add this to your .ebextensions YAML config to set it automatically:
    Resources:
      AWSEBV2LoadBalancerListener:
        Type: AWS::ElasticLoadBalancingV2::Listener
        Properties:
          LoadBalancerArn:
            Ref: AWSEBV2LoadBalancer
          Port: 80
          Protocol: HTTP
          DefaultActions:
            - Type: forward
              TargetGroupArn:
                Ref: AWSEBV2TargetGroup
          MaxRequestBodySize: 5242880000 # 5000MB in bytes
    
3. Fix Nginx Error Page Redirects Causing 405

A common gotcha: When Nginx hits a 413 Request Entity Too Large error, it might redirect to an error page using a GET request—but your client is still sending POST. This mismatch triggers a 405.

  • Fix: Update your Nginx config to return the 413 status code directly instead of redirecting:
    error_page 413 =413 /413.html;
    
    Create a simple 413.html file in your static assets folder to handle the error gracefully, or adjust the config to return a JSON response if needed.
4. Tweak Tomcat's Request Swallowing Limit

Spring Boot's embedded Tomcat has a maxSwallowSize setting (default 2MB) that limits how much of a rejected request body it will process. If your upload exceeds this, Tomcat might close the connection abruptly, leading to Nginx returning a 405 instead of the actual 413 error.

  • Fix: Add this to your application.properties:
    server.tomcat.max-swallow-size=-1 # Disable the limit entirely
    
5. Validate IAM Permissions for Multipart Uploads

Since you're using Transfer Manager for multipart uploads, ensure your EB instance's IAM role has all the necessary S3 permissions beyond just s3:PutObject:

  • s3:InitiateMultipartUpload
  • s3:UploadPart
  • s3:CompleteMultipartUpload
  • s3:AbortMultipartUpload

If any of these are missing, the multipart upload could fail silently and manifest as a 405 due to connection issues.

  1. Check Nginx error logs first to confirm the root cause.
  2. Verify ALB max request size is updated.
  3. Apply the custom Nginx config via .ebextensions.
  4. Add the Tomcat max-swallow-size setting.
  5. Double-check IAM permissions.

This should cover the most likely culprits for your 405 error with large uploads on EB. Let me know if you need to dive deeper into any of these steps!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 11:32:33