DEV Community

Misbah
Misbah

Posted on

Fixing 413 request entity to large on laravel + nginx

After deploying my Laravel application to an Ubuntu VPS using Nginx, I encountered this error when uploading a PDF:
413 Request Entity Too Large

The application was running normally, but every upload request failed instantly.

The Cause

The issue wasn't related to Laravel.

By default, Nginx limits the maximum size of the request body. When an uploaded file exceeds that limit, Nginx rejects the request before it reaches your Laravel application.

The Fix

Open your Nginx site configuration:
sudo nano /etc/nginx/sites-available/your-domain

Inside the server block, add:
client_max_body_size 100M;

Example:

server {
    listen 80;
    server_name example.com;

    root /var/www/project/public;
    client_max_body_size 100M;

    index index.php;
    ...
}
Enter fullscreen mode Exit fullscreen mode

Then verify the configuration:
sudo nginx -t

If everything looks good, reload Nginx:
sudo systemctl reload nginx

That's it.

After adding client_max_body_size, the upload worked immediately without making any changes to my Laravel application.

Takeaway

If you're getting:
413 Request Entity Too Large

on a Laravel application running behind Nginx, check your Nginx configuration first. In my case, simply adding:
client_max_body_size 100M;

inside the server block completely resolved the issue.

Top comments (0)