Andy
Andy

Reputation: 1002

Nginx error: client intended to send too large body

Periodically I get an error:

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.

My site is stored on AWS. I use rails + nginx + passenger.

Nginx error log:

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"

app log:

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

After a while, the error disappears. I have doubts that this is due to deployment, but I'm not sure. Could you please tell me, with what it can be related and how to fix such a problem?

Upvotes: 51

Views: 69720

Answers (4)

Rohit Ramani
Rohit Ramani

Reputation: 954

I have updated /etc/nginx/nginx.conf

in my case, I have added client_max_body_size in http block after sendfile on; as below

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

it is very important to put client_max_body_size after sendfile on;

Don't forget to restart nginx as below after updating the nginx.conf

For ubuntu

sudo service nginx restart

For Centos

sudo systemctl restart nginx

Upvotes: 14

Udara Seneviratne
Udara Seneviratne

Reputation: 2493

Add the following 3 commands inside the server clause of the nginx.conf

    sendfile on;
    client_max_body_size 20M;
    client_body_buffer_size 20M;

Upvotes: 6

Zohab Ali
Zohab Ali

Reputation: 9574

For me path of nginx.conf was /etc/nginx/nginx.conf.

In my case I just added client_max_body_size in http block and it worked for me

http {
    ...
    client_max_body_size 20M;
}    

Make sure to restart nginx after changing this config

Upvotes: 75

Pavel Mikhailyuk
Pavel Mikhailyuk

Reputation: 2877

Default Nginx config limits client request body with 1Mb.
You have to increase client_max_body_size to allow users to post large documents.
Don't miss with the context (http, server, location) of this derictive and don't forget to reload configuration or restart Nginx after that.

Upvotes: 33

Related Questions