≡ Menu

Nginx: 413 Request Entity Too Large Error and Solution

I‘m running nginx as a frond end to php based Apache+mod_fastcgi server. My app lets user upload images upto 2MB in size. When users trying to upload 1.5MB+ size image file using nginx reverse proxy, they are getting the following error on screen:

Nginx 413 Request Entity Too Large

How do I fix this problem and allow image upload upto 2MB in size using nginx web-server working in reverse proxy or stand-alone mode on Unix like operating systems?

You need to configure both nginx and php to allow upload size.

Nginx configuration

The client_max_body_size 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). To fix this issue edit your nginx.conf. Open the Terminal or login to the remote server using ssh client. Type the following command to edit your nginx.conf using a text editor such as vi or joe:
# vi /etc/nginx/nginx.conf
# vi /usr/local/nginx/conf/nginx.conf
Add the following line to http or server or location context to increase the size limit in nginx.conf, enter:

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

Save and close the file. Reload the nginx webserver, enter:
# /usr/local/nginx/sbin/nginx -s reload
# /sbin/nginx -s reload
OR use the following on RHEL/CentOS/Debian/Ubuntu Linux:
# service nginx reload

PHP configuration (optional)

Your php installation also put limits on upload file size. Edit php.ini and set the following directives

;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 = 2M

;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. Make sure you reload/restart back-end apache or nginx web server as per your setup. See “PHP Increase Upload File Size Limit” tutorial for more information.

Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 36 comments… add one }
  • lowry.shaw August 31, 2011, 6:34 am

    when i use
    client_max_body_size 2MB;
    there is something wrong:
    nginx: [emerg] “client_max_body_size” directive invalid value in conf/nginx.conf

    maybe you should use 2m not 2mb

    my nginx version:
    nginx: nginx version: nginx/1.0.5

  • Lukasz November 3, 2011, 10:40 pm
  • grissom January 4, 2012, 3:02 pm

    it should be:
    client_max_body_size 2M;

    • nixCraft January 4, 2012, 6:58 pm

      Thanks for the heads up!

    • Buminda October 21, 2013, 1:40 pm

      yes , it shoud be client_max_body_size 2M;

  • Jan August 21, 2012, 12:24 pm

    Thanks, man! Solved my problem!

  • Morten November 29, 2012, 5:39 pm

    Thanks a lot!!!

  • Joshua Pinter December 7, 2012, 5:37 pm

    Thanks for this!

    Something to note: I had `client_max_body_size` being set in a variety of files in the nginx directory. To quickly see if it is being set (and therefore causing overrides or conflicts) you can use the following line in the nginx directory.

    sudo grep -R ‘client_max_body_size’ ./*



  • Nick_K May 10, 2013, 10:22 am

    I would be happy to receive that kind of error (Nginx 413 Request Entity Too Large).

    Unfortunately, my browser (Firefox 20) shows me a page with the message “This page contains no data” when someone tries to upload a file more client_max_body_size

    I have tried to create a custom page 413 and get’s invoked when client_max_body_size get exceeded to no avail.

  • rad November 8, 2013, 7:05 pm

    This doc above is wrong, and should be updated

    nginx: configuration file /etc/nginx/nginx.conf test failed
    $ sudo nginx -t
    nginx: [emerg] “client_max_body_size” directive is not allowed here in /etc/nginx/nginx.conf:4
    nginx: configuration file /etc/nginx/nginx.conf test failed

    Solution: add this to http or server context!


    • nixCraft November 9, 2013, 6:31 am

      The faq has been updated. I appreciate your feedback and post.

  • Nanhe Kumar February 18, 2014, 1:03 pm

    If you have run bellow command
    # /usr/local/nginx/sbin/nginx -s reload
    # /sbin/nginx -s reload
    And you are getting error No such file or directory
    Simply restart your nginx
    sudo service nginx restart

  • Umair March 27, 2014, 11:03 pm

    Bro i am unable to save nginx file,how to save nginx file after setting limit,any special method?

  • Bill May 3, 2014, 5:47 am

    how about some directions that a common person can understand.
    I have 413 entity to large and can not get it off screen
    how do i do this to remove it.

    • Theodis Butler May 3, 2014, 5:50 pm

      This is only if you have a problem with a web application that you host on your own server.

      If it is on a website that is not under your control, then you need to contact the webmaster of that web site.

  • Felix May 21, 2014, 10:03 am

    Thx a lot. client_max_body_size was a right way.

  • Guy September 16, 2014, 7:43 pm

    somebody please make a step by step video.

  • Radek February 17, 2015, 2:52 am

    This article really helped me out. I wasn’t looking at the nginx logs until I read this.


  • Ryan April 7, 2015, 6:27 pm

    This was incredibly helpful. Thank you for the post!

  • Mohamed April 10, 2015, 5:49 pm

    Thank you! This solved my problem with a Drupal site where users wanted to uploaded PDF files.

  • Max Pittsley April 19, 2015, 9:15 am

    I’m getting this error when trying to upload a 2MB file even after setting client_max_body_size 100M; and reloading Nginx.

    • Peter G. April 29, 2015, 1:31 pm

      Did you also make the changes to the nginx.conf file? :)

      • Jeanne Keagy July 30, 2015, 12:28 pm

        Try to change it to 4M, that worked for me!!

  • Paris Nakita Kejser July 10, 2015, 2:32 pm

    Thanks a lot, you save my ass now, :) now i can send files on nginx when i need user uploads, have used lots of time to find this pcs of code! :)

  • Jeanne Keagy July 30, 2015, 12:27 pm

    I can’t thank you enough for posting this information, it was exactly what I needed to fix my 413 response error.

  • PSerg October 6, 2015, 8:25 am


  • janus rokkjær November 25, 2015, 6:25 pm

    Does not work any of the solutions sorry back to the writing board

  • Japo Domingo January 20, 2016, 10:43 pm


  • Syamala July 20, 2016, 6:48 am

    I increased size to 2M, as mentioned above in client_max_body_size 2M; and reloaded Nginx.
    But i see this error

    500 Internal Server Error

    500 Internal Server Error
    nginx/1.4.6 (Ubuntu)

  • xyz August 5, 2016, 9:49 am


  • Sascha October 14, 2016, 12:29 pm


  • Yogesh October 23, 2016, 8:48 pm

    Thank you very much.

  • Ricoyap November 2, 2016, 11:34 am

    it says “VI is not recognized as an internal or an external command,operable program or batch file” when i type it in CMD Windows 7 64 bit,can u help me?

    • E. November 8, 2016, 11:18 am

      Are you sure that you’re able running a webserver? Your OS tells you that it doesn’t know something about that command – so what do you think? Right. You have no VI installed. It is – like nginx – a software written for unix/linux not for windows. But there are ports for windows. So even you may use another editor or install VI from its homepage.

      • patrick January 16, 2017, 10:09 am

        just use another editor like nano

  • Michael Pankratov November 24, 2016, 5:53 pm

    Take a look at this file for default values as well:

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , ,