Website Vidya
DeploymentStep-by-Step Guide

How to Fix 406 Not Acceptable Error

What is the 406 Not Acceptable Error? The 406 Not Acceptable is an HTTP client error status code that indicates the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiati...

RR
Website Vidya TeamLead Systems Educator
Published:
10 min read
How to Fix 406 Not Acceptable Error
AI Executive SummaryCORE CIS AI

10 min read

What is the 406 Not Acceptable Error? The 406 Not Acceptable is an HTTP client error status code that indicates the server cannot produce a response matching the list of acceptable values defined in the request's proactive content negotiati...

Key Highlights
  • Understanding Fix 413 Request Entity Too Large Error: The Digital "No Entry" Sign
  • How to Fix 413 Request Entity Too Large Nginx Ubuntu: Step-by-Step
  • Troubleshooting & Verifying the Fix
Grounded in full engineering runbookCORE CIS Ai Engine

How to fix 413 request Entity too large Nginx Ubuntu error?

In the high-stakes world of web development and server administration, few errors are as simultaneously straightforward and frustrating as the HTTP 413 "Request Entity Too Large" error.

If you're managing a website or application on an Nginx server running Ubuntu, encountering this wall when users try to upload files or submit large forms can bring critical functionality to a grinding halt.

This comprehensive guide will demystify the error and provide you with proven, step-by-step solutions to resolve it for good.

Understanding Fix 413 Request Entity Too Large Error: The Digital "No Entry" Sign

At its core, the 413 Request Entity Too Large error is a server's way of saying, "What you're trying to send me is bigger than I'm allowed to accept." It's a protective measure. Nginx, by default, imposes limits on the size of client request bodies to prevent abuse, denial-of-service attacks, and to manage server resources efficiently.

When this error triggers, it typically means that the value of the client_max_body_size directive in your Nginx configuration is set lower than the size of the file or data a user is attempting to send. The default is often a mere 1 megabyte (1MB), which is insufficient for modern web applications involving image uploads, video content, document submissions, or large data exports.

The error manifests clearly in the Nginx error logs (typically /var/log/nginx/error.log) with entries like:
*[error] 1234#1234: *1 client intended to send too large body

Your mission, should you choose to accept it, is to adjust this limit appropriately and ensure the configuration is applied correctly across the necessary contexts.


How to Fix 413 Request Entity Too Large Nginx Ubuntu: Step-by-Step

Before editing any configuration files, it's a cardinal rule to create a backup. A simple typo can take your site offline. Use sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup for the main file, and similar logic for others.

Solution 1: The Primary Fix – Adjusting client_max_body_size in Nginx

This directive is the primary control knob for the request body size limit.

1(a). Open your Nginx configuration file

The main configuration file is usually /etc/nginx/nginx.conf. However, the most effective and organized place to set this is often within the specific server block (virtual host) for your website. These files are commonly found in /etc/nginx/sites-available/.

sudo nano /etc/nginx/sites-available/your-domain.conf

Or, if you have a default file:

sudo nano /etc/nginx/sites-available/default

1(b). Locate the server { ... } block for your domain or application, add or modify the client_max_body_size directive.

You can place it within the server block to apply it to the entire virtual host, or inside a specific location block (e.g., location /upload/) for more granular control.

server {
listen 80;
server_name yourdomain.com www.yourdomain.com;

# The key line: Increase the limit to, for example, 100MB
client_max_body_size 100M;

root /var/www/yourdomain.com/html;
index index.html index.htm index.nginx-debian.html;
...
}

Units Explained: You can specify the size in bytes (no suffix), kilobytes (k or K), megabytes (m or M), or gigabytes (g or G). 100M is 100 megabytes, a common starting point for many applications.

Save and close the file. In nano, press CTRL+X, then Y, then Enter.

Test the Nginx configuration for syntax errors: This crucial step verifies you haven't introduced any mistakes.

sudo nginx -t

You should see: nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload Nginx to apply the changes: If the test passes, reload Nginx. Unlike a restart, this applies changes with minimal downtime.

sudo systemctl reload nginx
# Or use the traditional signal: sudo nginx -s reload

Why This Works: You are directly increasing the maximum allowable payload size that Nginx will process for the defined context (server or location), allowing larger uploads to pass through to your application (like PHP-FPM, Node.js, or a Python backend).

Solution 2: Handling Upstream Proxies (PHP-FPM, FastCGI, etc.)

If your Nginx passes requests to a backend processor like PHP via PHP-FPM, you might still encounter issues after changing Nginx's setting. This is because the backend may have its own limits.

For PHP-FPM (common with WordPress, Laravel, etc.):

You must also adjust the upload_max_filesize and post_max_size directives in your PHP configuration.

Find the active PHP configuration file:

php --ini | grep "Loaded Configuration File"

Locate and modify the two key directives. Use CTRL+W in nano to search.

; Maximum allowed size for uploaded files.
upload_max_filesize = 100M

; Maximum size of POST data that PHP will accept.
post_max_size = 100M

Pro Tip: It's good practice to set post_max_size to be slightly larger than upload_max_filesize to account for form overhead.

Restart PHP-FPM to apply the changes.

sudo systemctl restart php8.2-fpm

Why This Works: Nginx handles the initial receipt of the request, but PHP-FPM handles the parsing of the POST data and file uploads. Both layers need their limits raised in harmony.

Solution 3: Adjusting Timeouts for Large Uploads

Very large files (like videos) may take a long time to upload. You might need to adjust Nginx's timeouts to prevent the connection from closing during the upload.

Add these directives within your http, server, or location block:

server {
client_max_body_size 500M;
client_body_timeout 300s; # Time to read the client body
proxy_read_timeout 300s; # Time to wait for a response from backend
fastcgi_read_timeout 300s; # Specific for PHP-FPM
...
}

Why This Works: These directives ensure that neither Nginx nor the upstream process gives up on the long-running request required for a massive upload.

Solution 4: Configuration in the http Block (Global Setting)

If you find yourself needing a universal limit across all sites on the server, you can set the directive in the main nginx.conf file within the http { ... } block.

  • Edit the main config: sudo nano /etc/nginx/nginx.conf
  • Inside the http block, add: client_max_body_size 20M; (for a sensible global default).
  • Test and reload Nginx as in Solution 1.

Warning: A very high global limit could increase your server's vulnerability to resource exhaustion attacks. Prefer setting limits per server or location block where possible.

Troubleshooting & Verifying the Fix

  • Clear Browser Cache: Old error messages can be cached. Use Ctrl+F5 or test in an incognito window.
  • Check the Correct Configuration File: Ensure you edited the Nginx site configuration that is actually enabled. Files in sites-available must be linked to sites-enabled. You can check with ls -la /etc/nginx/sites-enabled/.
  • Inspect the Logs: The Nginx error log (/var/log/nginx/error.log) is your best friend. Monitor it in real-time while testing an upload: sudo tail -f /var/log/nginx/error.log.
  • Check All Relevant location Blocks: If you have a specific location /wp-admin/ or location ~ \.php$ block, ensure a more restrictive client_max_body_size within it isn't overriding your server block setting.
  • Restart vs. Reload: When changing directives outside of the main http block, reload is usually sufficient. If changes don't take effect, a full restart can help: sudo systemctl restart nginx.
  • You can also check NGINX modules for the reference.

Best Practices & Security Considerations

  • Set Context-Specific Limits: Don't just set a 1GB limit globally. Apply a large limit (e.g., 500M) only to the specific upload endpoint (location /upload/) and a smaller, safer default elsewhere.
  • Implement Client-Side Validation: Always validate file size on the user's browser before upload. This provides immediate feedback but is not a substitute for server-side checks.
  • Implement Server-Side Application Logic: Your application (e.g., your PHP or Python code) should also check file sizes after upload and enforce business rules.
  • Monitor Resources: Large uploads consume bandwidth, disk I/O, and memory. Ensure your server has adequate resources and monitor for abuse.

Conclusion

Resolving the "413 Request Entity Too Large" error on Nginx and Ubuntu is a fundamental rite of passage for sysadmins and developers. It involves a clear understanding of the multi-layered request handling process: from the Nginx web server itself, through to any upstream application processors like PHP-FPM.

By methodically adjusting the client_max_body_size directive in the correct Nginx configuration context, and ensuring complementary settings in your backend (like upload_max_filesize in PHP), you can transform your server from a restrictive gatekeeper into a capable conduit for the data your application needs. Remember the mantra: test your configuration (nginx -t), reload the service, and verify through logs. Now, go forth and enable those large, seamless uploads.

Written by

Website Vidya Team

Technology educator and researcher at Website Vidya.

Discussion

0
Share your thoughts, ask a question, or suggest a tip...
Write →

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Deployment•

How to Install PDO Extension in PHP

PHP Data Objects (PDO) is one of the most important extensions in PHP for working with databases in a secure, consistent, and modern way. If you are building dynamic websites, APIs, CMS platforms, or enterprise applications, PDO is not opti...

RR
Rajesh Rai
Read More
Deployment•

25 Best Linux Commands Every Sysadmin Should Know

If you’ve spent any time managing Linux servers, you already know this truth: the command line is not optional. It’s where real troubleshooting happens, where performance issues are understood, and where outages are prevented before users e...

RR
Rajesh Rai
Read More
Deployment•

How to Fix Snapd Consuming High CPU / RAM on Linux

If you’ve ever opened your system monitor and noticed snapd quietly eating up your CPU or RAM, you’re not alone. Many Linux users—especially on Ubuntu and Ubuntu-based distributions—eventually run into this issue and wonder what’s going on ...

RR
Rajesh Rai
Read More