Still getting 413 Request Entity Too Large even after client_max_body_size 100M

时间:2016-04-21 22:26:35

标签: ruby-on-rails nginx digital-ocean

I'm using Rails and Nginx on Digital ocean and I've been trying to upload a 17.6 MB file and I'm still getting 413 Request Entity Too Large even after setting client_max_body_size 100M in my /etc/nginx/nginx.conf file.

Here's the snippet from the file:

http {

  ##
  # Basic Settings
  ##

  client_max_body_size 100M;
  sendfile on;
  tcp_nopush on;
  ...
}

After setting this I've used sudo service nginx reload. When that didn't work I've even done a full reboot using sudo shutdown -r now and then cap production puma:start from my local machine. I've also tried client_max_body_size 0; which, from what I understand should disable checking of file sizes entirely. Nothing works. Plus, in getting to this point, I've made some mistakes in the location of the client_max_body_size statement and in those situations the server has failed to start correctly giving a "Something went wrong" error, so I'm pretty sure the changes I'm making are to the right file.

Is there something I might be missing? Is there another place I'm missing to configure this? Is there something I'm missing in the way I'm currently configuring it? Any pointers would be greatly appreciated.

1 个答案:

答案 0 :(得分:15)

好。我想通了。按照how to configure nginx的数字海洋指南,我在文件type="h"中设置了client_max_body_size 100M。当然,改变那里的东西肯定会影响服务器的功能。特别是当我在那个文件中弄乱一些东西并且服务器停止运行时。

但是,我忘记了Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma这是我设置服务器的主要资源,它显示这些参数不是在上面的/etc/nginx/nginx.conf设置,而是在我的rails应用程序中设置是文件nginx.conf,其中的设置参数已包含语句

~/my_app/config/nginx.conf

所以我改变了这个陈述以及生产中的 client_max_body_size 10M; 文件。瞧!现在我可以上传最多100M的文件。