Whenever I upload a small file, such as an image, the data is saved successfully. However, when I upload an audio file I get this error: 413 Request Entity Too Large. The file sizes are around 8MB. The confusing part is that uploading these files in development process easily but now that the website is live, it doesn't work. I read that you can change the limit of the upload size but can't seem to figure it out. Another thing I read is that you should have files uploaded to a server, and you can use Nginx. I think I configured it; I typed the command
scp -r * root@[my ip address] /usr/share/nginx/html
and the files from my media folder were uploaded there. Now with that the files are not automatically put there, instead they are sent to the project's media folder. Shouldn't it automatically upload to the Nginx server?
your HTTPS server does not have client_max_body_size configured, so it is defaulting to 1M & causing this 413 (Request Entity Too Large) error. To fix this issue, you simply need to add client_max_body_size to BOTH the HTTP server block and the HTTPS server block, as shown in the example below: http { ...
What does “413 Request Entity Too Large” mean? A 413 HTTP error code occurs when the size of a client's request exceeds the server's file size limit. This typically happens when a client attempts to upload a large file to a web server, and the server responds with a 413 error to alert the client.
By default, nginx is configured to allow a client maximum body size of 1MB. The files you are uploading (~8MB) are larger than 1MB, which is why the 413 (Request Entity Too Large) error is being returned.
To fix this issue, simply edit nginx.conf and add a client_max_body_size
configuration like so:
######################
# HTTP server
######################
server {
...
listen 80;
server_name xxxx.com;
client_max_body_size 20M;
...
}
If you have HTTPS configured as well, be sure to add client_max_body_size
there as well:
######################
# HTTPS server
######################
server {
...
listen 443 default_server ssl;
server_name xxxx.com;
client_max_body_size 20M;
...
}
reload your server and you should be good!
[server]$ sudo service nginx reload
More info on client_max_body_size
here: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
Syntax: client_max_body_size size;
Default: client_max_body_size 1m;
Context: http, server, location
Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If the size in a request exceeds the configured value, the 413 (Request Entity Too Large) error is returned to the client. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables checking of client request body size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With