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:
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,
And voila! Restarting nginx and our server the error went away. 🙂