Changing the Upload File Size in Nginx

The other day I was trying to upload a large file to my spree store. The file wouldn’t upload. The web browser would initiate the request and spin for about 10 minutes like it was processing. Then, it would spit back a cryptic “413: The Connection Has Been Closed” error. It turns out that the default max file size for uploads through Nginx is only 2 Megabytes. To increase the file size, the client_max_body_size attribute should be added to the server directives in the nginx conf file for the application. Here is an example:

server {
  listen 80;
  server_name mycomain.com;
  root /var/www/myapp/public;

  client_max_body_size 50M;
  …

Now Nginx will allow up to a fifty megabyte upload. If the application uses SSL, both the normal and ssl directives will need the change.