413 Request Entity Too Large nginx/1.18.0 (Ubuntu)

This message occurs whenever I attempt to upload a file greater than 2M in wordpress. I have made the follow changes in order to increase the allowed file upload sizes:

In nginx.conf, I added

client_max_body_size 200M;

In php.ini, I modified

upload_max_filesize = 200M
max_file_uploads = 20
Post_max_size = 256M

In wp-config.php, I added

@ini_set( 'upload_max_filesize' , '200M' );
@ini_set( 'post_max_size' , '256M' );
@ini_set( 'memory_limit' , 256M' );

Even with these parameters set in the three configuration files I am still getting the message 413 Request Entity Too Large nginx/1.18.0 (Ubuntu)

Can anyone help?

Topic uploads nginx Wordpress

Category Web


FOR MORE EXPLANATION

You can add client_max_body_size or midify it in /etc/nginx/nginx.conf in 3 blocks

HTTP block : which affects all server blocks (virtual hosts)

http {
    ...
    # increase the limit
    client_max_body_size 100M;
} 

SERVER block : which affects a particular site/app.

server {
    ...
    # increase the limit
    client_max_body_size 100M;
}

LOCATION block : which affects a particular directory (uploads) under a site/app.

location {
    ...
    # increase the limit
    client_max_body_size 100M;
}

After having edited the configuration file you must restart your nginx server

$ systemctl restart nginx 

Problem Solved

In addition to increasing the maximum size in nginx.conf, php.ini and wp-conf.php files, it was necessary to raise the limit in the nginx server block for the site. I increased the default value of

client_max_body_size 2M;     to
client_max_body_size 200M;

and now all uploads go smoothly and quickly.

Hopefully, someone can tell me why I had to modify 4 separate files in order to raise the size limit when uploading files.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.