How to edit nginx.conf to increase file size upload

Jeff P. picture Jeff P. · Nov 3, 2014 · Viewed 142.6k times · Source

I want to increase the maximum file size that can be uploaded.
After doing some research online, I found that you have to edit the file 'nginx.conf'.
The only way I can currently access this file is by going through Putty and typing in the command:

vi /etc/nginx/nginx.conf

This will open the file but I have 2 questions now:

  1. How do I edit this file?
  2. I found online that you have to add the following line of code:

client_max_body_size 8M;

Where would I put this line of code in nginx.conf?

Answer

Matt Burrow picture Matt Burrow · Nov 3, 2014

Add client_max_body_size

Now that you are editing the file you need to add the line into the server block, like so;

server {
    client_max_body_size 8M;

    //other lines...
}

If you are hosting multiple sites add it to the http context like so;

http {
    client_max_body_size 8M;

    //other lines...
}

And also update the upload_max_filesize in your php.ini file so that you can upload files of the same size.

Saving in Vi

Once you are done you need to save, this can be done in vi with pressing esc key and typing :wq and returning.

Restarting Nginx and PHP

Now you need to restart nginx and php to reload the configs. This can be done using the following commands;

sudo service nginx restart
sudo service php5-fpm restart

Or whatever your php service is called.