[Fix] 413 Request Entity Too Large on Nginx web server

When I’m uploading a file which size is larger than 1MB using PHP on Nginx web server, I got this error message:

413 Request Entity Too Large

413 Request Entity Too Large

This error indicates that nginx limits file size that client can send to the server. And PHP configuration also has limit on upload file size. Therefore, I have to modify nginx and PHP configuration to fix this issue.

My server environment in this example:

  • Ubuntu 16.04
  • Nginx 1.10.0
  • PHP 7.0 fpm

If you use other version, path to configuration files may be different from the example.


  1. Login to the server and type this command to edit nginx.conf.
    sudo nano /etc/nginx/nginx.conf

    Note: You need to enter administrator password when using sudo command.

  2. Add the command below in http section. You can replace the number as file size limit that you want. In this example, I set it to 10M (10 Megabytes).
    client_max_body_size 10M;

    Modify nginx.conf

  3. Exit the editor by press Ctrl + X. You will be asked to save changes to the file, press Y.
    Save configuration
  4. Press Enter to save changes to the current filename.
    Save changes to nginx.conf
  5. Type this command to check nginx configuration file. If the syntax is ok, you can proceed to next step. Otherwise, you have to recheck the configuration file.
    sudo nginx -t

    Check nginx syntax

  6. If you already modified PHP configuration, skip to step 9.
    Modify PHP configuration. You can check location of php.ini using phpinfo(). Then, edit php.ini by type this command.

    sudo nano /etc/php/7.0/fpm/php.ini

    Edit php.ini

  7. Change post_max_size to 10M
    Change post_max_size value
  8. Change upload_max_filesize to 10M and save the file.
    Change upload_max_filesize value
  9. Restart nginx and php services by type these command:
    sudo service nginx restart
    sudo service php7.0-fpm restart

    Restart nginx and php service

  10. If there is no error, your PHP configuration should be updated as in the figure below.
    Updated PHP configuration
  11. Now I can upload a large file using PHP on the server.
    Upload large file size


One Response

  1. Ken August 10, 2017

Leave a Reply