Fixing the "Request Entity Too Large" Issue with Ghost Blogs on Digital Ocean
Recently, when writing up a short case study, I was attempting to upload some high-resolution images of my mockups to the blog and ran into the following error: “Request Entity Too Large”.
I googled around, and though some people had provided what worked for them, it took much longer than expected to find a solution to my problem. It turns out that the error I was facing was linked to the kind of file I was uploading, as opposed to its size, but more on that later. First, the TLDR; of the most common solution.
The Issue
I run ghost with the provided DigitalOcean 1-Click App setup on their smallest machine for $5/mo. This ghost installation runs with Nginx, which, by default, caps their maximum file upload in a given attempt to 1MB. So, if you try and upload an image larger than 1MB, you’ll be out of luck, unless you edit the underlying Nginx configuration.
The Solution
In most cases, changing the nginx.conf
will fix the problem. You will be either editing or adding the client_max_body_size
property to this file. The steps to do so are as follows:
First, ssh into your DigitalOcean droplet:
ssh root@YOUR.IPV4.ADDRESS.HERE
Next, open up the Nginx config file with an available editor such as nano.
nano /etc/nginx/nginx.conf
Look for the http
section and add/edit the line client_max_body_size 10M;
at the top.
http {
##
# Basic Settings
##
client_max_body_size 10M;
…
}
Make sure that you write out with Ctrl O
to save and exit the file with Ctrl X
.
The last step is to restart the Nginx server for the changes to take effect.
service nginx reload
At this point, you can go back to your ghost setup, refresh and try uploading your images again.
If This Does Not Work:
Try editing the ghost config instead.
Once again, ssh
into your droplet, and open up the following file for editing.
nano /var/www/ghost/system/files/YOUR-DOMAIN.conf
In this file, find the client_max_body_size
parameter and change the value to your desired upload capacity.
client_max_body_size 10M;
Once again, write out and exit before restarting both the ghost instance and the Nginx server.
ghost restart
service nginx restart
You should now (hopefully) be able to upload larger files with no issues!
A Note on Max Upload Size:
The default upload size is so small in part because capping the upload size is a preventative security measure against DDoS attacks against your services. If you are the only writer of your blog then lifting this cap shouldn’t be an issue, but be weary of the limit that you set. For example, don’t set the limit to 1000M unless you are actually going to be uploading files that large, set the limit to allow for only what you need.
The Solution to my Specific Problem
So, it turns out that even after going through all of the steps above, I still wasn’t able to upload a certain image to ghost, despite being able to upload other images of size larger than 1MB. So, my fix had worked, but not for this one crucial image. It turned out to be an issue with the image's format. When writing a blog post, I generally write in Evernote first, before moving over the edited version to ghost. This usually isn’t a problem, apart from when Evernote can handle a certain image format and ghost cannot. All of my image uploads are in PNG format, but this one picture from my case study somehow ended up being something weird, and copying it from Evernote broke the upload. Interestingly enough, despite this being a file type problem, which should elicit a 415 Unsupported Media Type
error I got a 413 Request Entity Too Large
error, which made diagnosing the issue much more complicated than it needed to be.
Once I realized what was going on, I made sure that the image was saved correctly as a PNG, and it uploaded and saved just fine.
Hopefully this guide helped spare you some headache - I know I would have appreciated a more comprehensive guide, with a few possible issues and their solutions, instead of having to dig around for far too long trying out different things. Happy ghosting!