Tuesday, 15 October 2024

Fix the 413 Request Entity Too Large error in Laravel running on Nginx

1. Increase client_max_body_size in Nginx

The client_max_body_size directive in Nginx controls the maximum allowed size of the client request body, which includes uploaded files.

Steps:

  • Open your Nginx configuration file. This could be located at /etc/nginx/nginx.conf or in a site-specific configuration file under /etc/nginx/sites-available/.
sudo nano /etc/nginx/nginx.conf
  • Add or update the client_max_body_size directive inside the http block (or inside server or location blocks, if you prefer):
http { client_max_body_size 100M; }
$ sudo service nginx reload
 

2. Increase post_max_size and upload_max_filesize in PHP

Nginx will pass the request to PHP, and PHP has its own limits. You need to increase the upload_max_filesize and post_max_size in your php.ini file.

Steps:

  • Find your php.ini file. It is usually located in /etc/php/7.x/fpm/php.ini (on Linux) or C:\xampp\php\php.ini (on Windows).

  • Open the file and increase the following values:

upload_max_filesize = 100M post_max_size = 100M
 
Thank you

No comments:

Post a Comment

Golang Advanced Interview Q&A