HTTP Error 413: Request Entity Too Large

Last week, we were working on an image uploader using the gem PaperClip. We set our PaperClip Size Validator to only accept images that are less than 2 Megabytes. In our file model:

Screen Shot 2015-06-13 at 10.38.30 PM

Testing on local setup, uploading a 1.7 MB works fine. But when we tried it on our staging environment (using Nginx), upload does not push through and we are given a HTTP Error 413: Request Entity Too Large.

Researching around the internet, we found out that it has something to do with the client_max_body_size config of Nginx. Following the instructions we found on the net, we looked for our nginx.conf file in /etc/nginx but the config for client_max_body_size is not there. Taking into account, that our server host multiple sites (one for public use and another for admin),  we checked out the sites-enabled folder (/etc/nginx/sites-enabled), and edited each of our sites’ config file.

The client_max_body_size setting can be found under the server block. It was initially set to 1 MB that is why 400KB files are allowed but 1.7 MB files are not on our staging setup.

We set each of our sites’ config files to have a client_max_body_size of 2 MB,

Screen Shot 2015-06-13 at 10.47.51 PM

And voila! Restarting nginx and our server the error went away. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s