First, you need to edit the /etc/nginx/nginx.conf file by typing the vi command:


$ sudo vi /etc/nginx/nginx.conf

In HTTP (server/location) section add the following directive to set the maximum allowed size in 10MB:


client_max_body_size 10M;

Save and close the file.


Test nginx configuration for error


Run the following command:


$ sudo nginx -t

Sample outputs:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


If no error means, restart the nginx web server.


$ sudo systemctl reload nginx

OR

$ sudo service nginx reload

Verify the configuration by uploading a large file. Make sure you watch nginx error log too:


$ sudo tail -f /var/log/nginx/error.log


How to configure php to accept upload up to 10MB

Edit your php.ini file and make sure the following two-line present in it:


$ sudo vi /etc/php.ini

Append or edit as follows:

upload_max_filesize=10M
post_max_size=10M


Save and close the file. Restart your Nginx PHP-fpm service:


$ sudo systemctl start php-fpm

OR

$ sudo /etc/init.d/php-fpm restart

OR

# /usr/local/etc/rc.d/php-fpm restart

Now upload a file and test it.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket