I have installed Nginx on one of my servers. The target was to run a blog there. After everything was set up, the blog was running, but I faced a problem while uploading a file.
The server was returning an Nginx error – 413 – Request Entity Too Large.
So this is an error message returned by Nginx, and it was related to file size. The file that I was trying to upload was surely bigger than the allowed size.
The fix is simple – we have to allow large file sizes in our Nginx configuration.
So, fix this issue. Open file /etc/nginx/nginx.conf in your preferred editor(maybe vim, or a maybe more simple one like nano).
Make sure you are logged in as root, as you will need permission to edit the conf and restart the Nginx server.
sudo vim /etc/nginx/nginx.conf
And the configuration that we are looking for is client_max_body_size. If that is not already present, then add that line.
In the place of 20M, you can put a bigger number if you prefer that.
Then restart your Nginx server. I did the following for my server:
sudo service nginx reload
Or you can restart the server by using:
sudo service nginx restart
That’s all for Nginx conf.
But there are other things that you also need to consider. Like, I am using PHP for my blog, so there are also some file/request size limitations in PHP configuration. If you are also using PHP, then consider changing the following configuration:
# For maximum allowed file size for upload upload_max_filesize = 20M # For maximum allowed size for request/body of the request post_max_size = 30M # Change memory limit if needed memory_limit = 32M
If you are using PHP-FPM, then you need to restart that by one of the following commands:
sudo systemctl restart php-fpm # or use this command sudo systemctl restart php7.2-fpm.service # or use this sudo /usr/local/etc/rc.d/php-fpm restart
If you are still facing a problem, check the directory’s permission where you are trying to upload the file. If you are using any other programming language, then also check their allowed permission.