CentOS & Linux & PHP

WordPress HTTP Error on Nginx

It happened to me few days back when i try to upload an image via WordPress media library over 1MB of size. WordPress would throw an error ‘HTTP Error‘. Well the error is not that descriptive and one would think what could be the problem, is it a permission issue. Most probably not because you may upload images less 1MB and that got uploaded. So its not permission issue. Then what could be the issue?, the answer is simple.

If you have your own VPS lets say with DigitalOcean OR Linode etc running Nginx and WordPress. Chances are that you may have missed one line to add to your server block in nginx.conf OR any conf file inside conf.d dir which your server is listening to. So lets fix this, login to your server via terminal and type if your are root already.

vim or vi or nano choice is yours, i prefer vim. Now default.conf may be different for you, so change it to the file you want to edit. If your server is listening to nginx.conf then run the 2nd command.

vim /etc/nginx/conf.d/default.conf

OR

vim /etc/nginx/nginx.conf

Inside that file(s) look for server block and add the following line to it:

client_max_body_size 4m;

4m means upload file limit would be 4MB, change it your desired number. Check if there is no error in the conf file:

nginx -t

If no errors, restart the web server. If got errors, check the error and fix that.

systemctl restart nginx

Thats pretty much it.

NOTE: If you get max upload file size 2MB, that means your php.ini only allow 2MB. For this to make it work open /etc/php.ini and change these:

upload_max_filesize = 8M

post_max_size = 10M

And now restart php-fpm:

systemctl restart php-fpm

systemctl restart nginx

M M Arif

Founder of www.therandombits.com and anl4u.com. Husband. Father. Senior Software Engineer. Linux enthusiast, using multiple Linux operating systems for personal use and work. A self taught programmer who love to code and share. Fan of open source and community projects.

You may also Like

Leave a reply

Your email address will not be published. Required fields are marked *

×