本文介绍了即使在client_max_body_size 100M之后,仍然获得413个请求实体太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Digital ocean上使用Rails和Nginx,并且试图上传17.6 MB的文件,即使在/etc/nginx/nginx.conf中设置client_max_body_size 100M之后,我仍然会得到413 Request Entity Too Large文件.

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.

这是文件中的摘录:

http {

  ##
  # Basic Settings
  ##

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

设置后,我使用了sudo service nginx reload.如果不起作用,我什至使用sudo shutdown -r now,然后从本地计算机中的cap production puma:start,进行了完全重启.我也尝试过client_max_body_size 0;,据我了解,应该完全禁用文件大小检查.什么都行不通.另外,在这一点上,我在client_max_body_size语句的位置上犯了一些错误,并且在这些情况下,服务器未能正确正确启动,并出现出了点问题"错误,因此,我很确定我正在对正确的文件进行更改.

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.

推荐答案

好的.我想通了.遵循如何配置nginx ,我在文件/etc/nginx/nginx.conf中设置了client_max_body_size 100M.可以肯定的是,在那里进行更改肯定会影响服务器的工作.尤其是当我将文件中的内容弄乱了并且服务器停止运行时.

Okay. I figured this out. Following the Digital Ocean guide for how to configure nginx, I was setting client_max_body_size 100M in the file /etc/nginx/nginx.conf. And for sure, changing things there definitely had impact on what the server did. Especially when I would mess something up in that file and the server stopped functioning.

但是,我在在具有Capistrano,Nginx和Puma的Ubuntu 14.04上部署Rails应用(这是我设置服务器的主要资源),它表明这些参数并未在上面的nginx.conf,但是在我的Rails应用程序中是文件~/my_app/config/nginx.conf,其中的设置参数已经包含了语句

However, I had forgotten that in Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma which was my main resource for setting up my server, it shows that these parameters get set up not in the above nginx.conf but rather in my rails app there is the file ~/my_app/config/nginx.conf in which the setup parameters already included the statement

  client_max_body_size 10M;

因此,我在生产时也更改了该语句以及/etc/nginx/nginx.conf文件中的语句.瞧!现在,我可以上传最多100M的文件.

So I changed that statement as well as in the /etc/nginx/nginx.conf file on production. Voila! Now I can upload files up to 100M.

这篇关于即使在client_max_body_size 100M之后,仍然获得413个请求实体太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:30