DEV Community

Cover image for How to Fix "Request Entity Too Large" Error in Nginx
Ashirbad Panigrahi
Ashirbad Panigrahi

Posted on

How to Fix "Request Entity Too Large" Error in Nginx

Facing the "413 Request Entity Too Large" error in Nginx when uploading files or submitting large forms? This error is caused by a default limit on request body size—only 1MB is allowed unless you configure it otherwise. Here’s how to quickly and safely increase the upload size in Nginx on Ubuntu Linux, ensuring your website can handle large file uploads and improve user experience.


1. Access Your Nginx Configuration File

Use the terminal to open your main Nginx configuration file with sudo privileges:

sudo vim /etc/nginx/nginx.conf
Enter fullscreen mode Exit fullscreen mode

2. Find and Edit the Appropriate Block

Look for the http block (usually around line 12) in your config file.

Add or update the following line inside this block to increase the maximum allowed body size—for example, to allow uploads up to 100MB:

client_max_body_size 100M;
Enter fullscreen mode Exit fullscreen mode

You can also add this directive inside a specific server or location block to limit the change to certain parts of your website, improving security[9][12].


3. Save and Exit Vim

After making your change, save the file and exit vim with your keyboard:

  • Write changes: Press Esc, then type :w
  • Quit: Type :q
  • Write and quit: Press Esc, then type :wq

4. Reload Nginx to Apply Changes

Check your configuration for syntax errors, then reload Nginx to activate the new limit:

sudo nginx -t   # Check for errors
sudo systemctl reload nginx   # Apply changes without downtime
Enter fullscreen mode Exit fullscreen mode

Top comments (0)