简体   繁体   English

Dokku(数字海洋)client_max_body_size node.js

[英]Dokku (Digital Ocean) client_max_body_size node.js

So I've just pushed my app to Dokku (Digital Ocean) - and get the following error returned from an ajax post:所以我刚刚将我的应用程序推送到 Dokku(数字海洋) - 并从 ajax 帖子返回以下错误:

POST http://example.com/foo 413 (Request Entity Too Large) POST http://example.com/foo 413(请求实体太大)

A quick google shows this problem is due to client_max_body_size being too low.快速谷歌显示这个问题是由于 client_max_body_size 太低造成的。 So I've SSH'd into the server, opened up the apps nginx.conf and increased it as per instructions here:所以我已经通过 SSH 进入服务器,打开应用程序 nginx.conf 并按照此处的说明增加它:

client_max_body_size 100M;

https://github.com/progrium/dokku/issues/802 https://github.com/progrium/dokku/issues/802

However, I still have the same problem... Do I need to restart a process or something?但是,我仍然有同样的问题......我需要重新启动一个进程还是什么? I tried restarting the dokku app - but all this did was to overwrite my nginx.conf file.我尝试重新启动 dokku 应用程序 - 但所做的只是覆盖我的 nginx.conf 文件。

@Rob s answer is correct, but has the problem that the changes are not persisted, because the nginx.conf might become regenerated eg when deploying. @Rob的答案是正确的,但是存在更改未持久存在的问题,因为nginx.conf可能会在部署时重新生成。

The solution I use is outlined in this github commit https://github.com/econya/dokku/commit/d4ea8520ac3c9e90238e75866906a5d834539129 . 我使用的解决方案在此github提交https://github.com/econya/dokku/commit/d4ea8520ac3c9e90238e75866906a5d834539129中列出。

Basically, dokkus default nginx templates include every file in the nginx.conf.d/ subfolder into the main server configuration block, thus 基本上,dokkus默认的nginx模板将nginx.conf.d/子文件夹中的每个文件都包含在主server配置块中,从而

mkdir /home/dokku/myapp/nginx.conf.d/
echo 'client_max_body_size 50M;' > /home/dokku/myapp/nginx.conf.d/upload.conf
chown dokku:dokku /home/dokku/myapp/nginx.conf.d/upload.conf
service nginx reload

Will create a file that is merged into the nginx.conf (at nginx startup time I believe) and kept untouched by dokku as long as you do not use interfering plugins or define another nginx template (as of 2017/08). 将创建一个合并到nginx.conf的文件(在我相信的nginx启动时)并且只要你不使用干扰插件或定义另一个nginx模板(截至2017/08),就不会被dokku保持不变。

This has been updated in Dokku and can be done from the CLI: dokku nginx:set node-js-app client-max-body-size 50m .这已在 Dokku 中更新,可以从 CLI 完成: dokku nginx:set node-js-app client-max-body-size 50m https://dokku.com/docs/networking/proxies/nginx/#specifying-a-custom-client_max_body_size https://dokku.com/docs/networking/proxies/nginx/#specifying-a-custom-client_max_body_size

I figured it out - I had to cd into the apps directory (as per github instructions: https://github.com/progrium/dokku/issues/802 我想通了 - 我不得不进入应用程序目录(根据github说明: https//github.com/progrium/dokku/issues/802

The right file to modify is /home/dokku//nginx.conf and as @dipankar mentioned, you should add a client_max_body_size 20M; 要修改的正确文件是/home/dokku//nginx.conf,并且提到@dipankar,你应该添加一个client_max_body_size 20M; line to the server scope. 行到服务器范围。

and then I typed 然后我输入

reload nginx

into the command line. 进入命令行。 All works :) 所有的作品:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM