Nginx 错误:客户端打算发送太大的正文



定期出现错误:

This site can't be reached.
The webpage at https://example.com/document might be temporarily down or it my have moved permanently to are new web address.

我的站点存储在 AWS 上。 我使用导轨 + nginx + 乘客。

Nginx错误日志:

client intended to send too large body: 3729822 bytes, 
client: 172.42.35.54, server: example.com, 
request: "POST /document HTTP/1.1", host: "test.example.com", 
referrer: "https://test.example.com/document/new"

应用日志:

ActionController::RoutingError (No route matches [GET] "/document")

一段时间后,错误消失。我怀疑这是由于部署,但我不确定。你能告诉我,它可以与什么相关以及如何解决这样的问题吗?

对我来说,nginx.conf的道路是/etc/nginx/nginx.conf

就我而言,我只是在http block中添加了client_max_body_size,它对我有用

http {
...
client_max_body_size 20M;
}    

确保在更改此配置后restart nginx

默认 Nginx 配置将客户端请求正文限制为 1Mb。
您必须增加client_max_body_size以允许用户发布大型文档。
不要错过这个德里克的上下文(http,服务器,位置),不要忘记重新加载配置或重新启动Nginx。

我已经更新了/etc/nginx/nginx.conf

就我而言,我在sendfile on;之后添加了http blockclient_max_body_size,如下所示

http {
...
sendfile on;
client_max_body_size 20M;
}

client_max_body_size放在sendfile on;之后

非常重要不要忘记在更新nginx.conf后重新启动nginx,如下所示

对于 ubuntu

sudo service nginx restart

对于森托斯

sudo systemctl restart nginx

nginx.confserver子句中添加以下 3 个命令

sendfile on;
client_max_body_size 20M;
client_body_buffer_size 20M;

最新更新