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

And*_*ndy 14 ruby ruby-on-rails nginx amazon-ec2 amazon-web-services

我定期收到一个错误:

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.
Run Code Online (Sandbox Code Playgroud)

我的网站存储在 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"
Run Code Online (Sandbox Code Playgroud)

应用日志:

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

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

Pav*_*yuk 21

默认Nginx 配置将客户端请求正文限制为 1Mb。
你必须增加client_max_body_size允许用户张贴大文件。
不要错过此派生词的上下文(http、服务器、位置),并且不要忘记在此之后重新加载配置或重新启动 Nginx。


Zoh*_*Ali 18

对我来说nginx.conf/etc/nginx/nginx.conf.

就我而言,我只是添加client_max_body_sizehttp block它,它对我有用

http {
    ...
    client_max_body_size 20M;
}    
Run Code Online (Sandbox Code Playgroud)

确保restart nginx在更改此配置后


roh*_*ani 6

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

就我而言,我在后面添加client_max_body_sizehttp block如下sendfile on;内容

http {
    ...
    sendfile on;
    client_max_body_size 20M;
}
Run Code Online (Sandbox Code Playgroud)

client_max_body_size放在后面非常重要sendfile on;

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

对于Ubuntu

sudo service nginx restart
Run Code Online (Sandbox Code Playgroud)

对于 Centos

sudo systemctl restart nginx
Run Code Online (Sandbox Code Playgroud)


Uda*_*tne 5

server在子句中添加以下 3 个命令nginx.conf

    sendfile on;
    client_max_body_size 20M;
    client_body_buffer_size 20M;
Run Code Online (Sandbox Code Playgroud)