LogIn
I don't have account.

Getting 413 Payload Too Large Error in Nginx on Elastic Beanstalk After Hosting My Website

Hi everyone,
I recently deployed my web application on AWS Elastic Beanstalk and everything is running fine except for one issue whenever I try to upload a large file (a large photo), I get this error:

413 Payload Too Large 

It looks like Nginx is rejecting my requests when I try to upload files above a certain size.

My setups :

  • I’m using AWS Elastic Beanstalk to host my .NET Core / Node.js web application.
  • The environment is configured with Nginx as a reverse proxy.
  • Small uploads (like profile pictures) work fine, but when I upload files around 5–10MB or higher, the server immediately returns HTTP 413 (Request Entity Too Large).

What I’ve tried so far :

  • Restarted the environment.
  • Checked my application logs, the request doesn’t even reach my app.
  • Searched online and found mentions of client_max_body_size, but I’m not sure where to configure it in Elastic Beanstalk.

Can someone please guide me how to increase the file upload limit properly on AWS Elastic Beanstalk so that Nginx allows larger files?
Also, do I need to redeploy after changing the configuration?

Thanks in advance for any help!


Please pay attention to update your answer.

Update Your Answer care fully. After saving you can not recover your old answer

Carefully Update Your Answer!!

Fix 413 Payload Too Large — Nginx on Elastic Beanstalk

Step 1: Create the Nginx Config

SSH into your Elastic Beanstalk instance and create a new configuration file that Nginx will automatically load at startup.

sudo nano /etc/nginx/conf.d/elasticbeanstalk/01_client_max_body.conf

If the elasticbeanstalk folder doesn’t exist, create the config directly under /etc/nginx/conf.d/ instead:

sudo nano /etc/nginx/conf.d/01_client_max_body.conf

Step 2: Add the Limit Setting

Paste this inside the file:

client_max_body_size 50M;

Then save and exit:
Ctrl + O,Enter,Ctrl + X

Step 3: Reload Nginx

To apply the change, reload Nginx:

sudo service nginx reload

Step 4: Confirm It’s Active

Run this to check the loaded config:

sudo nginx -T | grep client_max_body_size

You should see:client_max_body_size 50M;

This confirms your Nginx configuration has been successfully updated.

Please pay attention to update your answer.

Update Your Answer care fully. After saving you can not recover your old answer

Carefully Update Your Answer!!

This is a very common issue on Elastic Beanstalk environments that use Nginx as the proxy layer.

Root Cause:

Elastic Beanstalk environments use Nginx as a reverse proxy in front of your app.
By default, Nginx limits the request size using this directive:

client_max_body_size 1M;

That means any file larger than 1 MB gets rejected before it reaches your application.

Solution: Increase the client_max_body_size limit

You need to tell Nginx to allow larger payloads.
The correct way depends on which Elastic Beanstalk platform you’re using.

1. For Amazon Linux 2 (modern platforms):

Elastic Beanstalk now supports custom Nginx configuration through the .platform directory.

Step 1:

In your project root, create the following folders:

.platform/nginx/conf.d/

Step 2:

Inside the conf.d folder, create a file named:

01_client_max_body_size.conf

Step 3:

Add this line inside that file:

client_max_body_size 50M;

(You can increase the value -> 50M = 50 Megabytes.)

Step 4:

Deploy your app again:

eb deploy

When Beanstalk deploys, it automatically merges your .conf into Nginx’s configuration.

Step 5:

After deployment, test uploading your file again ,it should work without any 413 error.

2. For older Elastic Beanstalk (Amazon Linux 1) platforms:

If you’re on an older stack that doesn’t support .platform/, you’ll use .ebextensions/.

Create a file:

.ebextensions/nginx.config

Add the following:

files:
  "/etc/nginx/conf.d/proxy.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      client_max_body_size 50M;
container_commands:
  01_reload_nginx:
    command: "service nginx reload || true"
 

Then redeploy your app.

 How to Verify the Change:

After deployment, SSH into your EC2 instance and run:

sudo cat /etc/nginx/conf.d/01_client_max_body_size.conf

You should see:

client_max_body_size 50M;

It means your configuration is applied correctly!