How to Fix “client intended to send too large body” in Nginx

By Lowell Heddings on May 26th, 2017

If you’re getting the obnoxious “client intended to send too large body” error like I am, you’re in luck because today we’re going to solve the article. In fact, I’m writing this paragraph before I’ve even solved the error in anticipation that I will solve it and have an article to post.

What’s actually happening is that I just built this site on a new server, and I was trying to upload a large image for an article that I’m writing. The image is only 1.5mb but on the web that’s very large, so nginx is probably blocking it. Usually you can just upload a smaller image and it’ll be fine, but why let the error keep us down?

Most likely the problem is a bad configuration somewhere. And… sure enough.

Fixing the Error

You’re going to need to go find your nginx configuration files. On my server they are located under /usr/local/nginx/conf/ and there is a sites-enabled folder that has the actual site file. You can either add this option under nginx.conf or the specific site config file found in the sites-enabled folder. What you’re looking for is a section that looks kinda like this:

server {
        listen  80;
        server_name www.thisismysite.com;

Once you find that, you know you’re in the right place. Underneath that, you’re going to want to add this line, which will set the max body size for an incoming client request to 5 MB. You can change it to 10MB or 100MB or any other value that you’d prefer, but 5MB was a good value for our purposes.

client_max_body_size 5M;

Of course, you should consider carefully whether allowing larger requests is something you want to do, because it can be a security issue to allow huge requests to come in, especially if you get hit by a DDoS or just a misconfigured client script.