nginx error – 413 Request Entity Too Large

I was getting an error when trying to upload and attach images larger than 2MB via Wordpress. I discovered that nginx has a configuration setting called client_max_body_size that is default set to 1M. To change this, I altered my nginx vhost configuration and added the following line:

server {
    server_name techish.net www.techish.net;
    root /var/www/techish.net;
    include /etc/nginx/fastcgi_php;
    **client_max_body_size 5M;**
    location / {
        index index.php;
        if (!-e $request_filename) {
            rewrite ^(.*)$  /index.php last;
        }
    }
}

This should suffice for most of my image uploading needs. However, if you have large uploads you perform to your server through nginx, you may need to increase that! Reload nginx

/etc/init.d/nginx reload

Here’s nginx configuration’s HttpCoreModule documentation on this configuration value:

client_max_body_size syntax: client_max_body_size size default: client_max_body_size 1m context: http, server, location Directive assigns the maximum accepted body size of client request, indicated by the line Content-Length in the header of request. If size is greater the given one, then the client gets the error “Request Entity Too Large” (413). It is necessary to keep in mind that the browsers do not know how to correctly show this error.

Note: You’ll need to match your PHP value also. /etc/php5/cgi/php.ini

upload_max_filesize = 5M

Restart php-cgi

/etc/init.d/php-cgi restart
#NGINX #WordPress