How to fix 413 request entity too large error in Nginx

Written By:- Santosh Prasad

If you are using Nginx as front end to php based Apache+mod_fastcgi server and if user try to upload 1.5MB+ files and image using Nginx reverse proxy, they will get the following error on screen:

Nginx 413 Request Entity Too Large

In this article I will explain how you can fix this error. To fix this error you will need to configure Nginx and PHP to allow upload size.

Nginx Configuration

The client_max_body size directive assigns the maximum accepted body size of client request, it indicate the line Content-Length in the header of request. If the size is greater the given one then the client get the error “Request Entity Too Large“. To fix this issue you will need to edit nginx.conf file.

# vim /etc/nginx/nginx.conf


# vim /usr/local/nginx/conf/nginx.conf

Add the following the to http or server or location context to increase the size limit in nginx.conf file.

# set client body size to 10M #
client_max_body_size 10M;

Save and close the file.

Now reload the Nginx webserver.

# service nginx relaod


# /usr/local/nginx/sbin/nginx -s reload


# /sbin/nginx -s reload

PHP Configuration

Now edit the php.ini file to set the upload file size limit. Set the following directives in php.ini.

;This sets the maximum amount of memory in bytes that a script is allowed to allocate
memory_limit = 32M

;The maximum size of an uploaded file.
upload_max_filesize = 10M

;Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize
post_max_size = 3M 

Save and close the file.

Now reload or restart back-end Apache and Nginx web server.


About Author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Other Post by Santosh Prasad

Visit All Post

Related Article

You may also Like

Leave a Comment