Back to Blog
Bug Fixes•1 min read

Fix '413 Request Entity Too Large' on File Uploads

Scaleup Infotech Team
Scaleup Infotech Team

Custom Software & Business Automation

NginxPHPUploadsDevOps

In this guide

A simple guide to this issue: '413 Request Entity Too Large' on File Uploads. Learn why it happens, what to check first, and how to fix it.

A 413 means some layer between the browser and your code rejected the request body for being too large. You usually have to raise the limit in two or three places — Nginx, PHP, and the framework.

The Error

413 Request Entity Too Large

Fix 1: Nginx

nginx
http {
    client_max_body_size 50M;   # in the http, server, or location block
}

Then reload: sudo nginx -t && sudo systemctl reload nginx.

Fix 2: PHP (if applicable)

ini
; php.ini
upload_max_filesize = 50M
post_max_size = 52M     ; must be >= upload_max_filesize

Fix 3: Node / Express

javascript
app.use(express.json({ limit: "50mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: true }));

Restart Everything

PHP changes need an php-fpm restart; Nginx needs a reload. Forgetting to restart is why people think the fix 'didn't work'.

Relevant Scaleup Infotech Services

Share this article:

Keep Reading

Ready to implement these ideas?

Discuss Your Project