Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: client intended to send too large body

I am using django-resto to upload my media files to remote server. However when I tried to upload, it gives me django_resto.storage: Failed on create.

And Log generated below messages,

open() "/var/www/media/media/events/video/clipcanvas_14348_H264_640x360.mp4"
failed (2: No such file or directory),
    client: 172.17.42.1,
    server: ,
    request: "HEAD /media/events/video/clipcanvas.mp4 HTTP/1.1",
    host: "IP:8081"

client intended to send too large body:
    body: 2139606 bytes,
    client: *.*.*.*,
    server: ,
    request: "PUT /media/events/video/clipcanvas.mp4 HTTP/1.1",
    host: "IP:8081"

Can someone please explain why I am getting such an error?

Settings for Media Server,

DEFAULT_FILE_STORAGE = 'django_resto.storage.DistributedStorage'
RESTO_MEDIA_HOSTS = ['IP:8081']

Nginx configuration,

server { 
    listen 192.168.0.10; 
    location / { 
        root /var/www/media; 
        dav_methods PUT DELETE; 
        create_full_put_path on; 
        dav_access user:rw group:r all:r; 
        allow 192.168.0.1/24; deny all;
    } 
}
like image 927
Ahsan Avatar asked May 27 '15 11:05

Ahsan


1 Answers

This issue will be caused by nginxs low default client_max_body_size value (1MB).

You will need to set the client_max_body_size <value> to something higher in one of the following context blocks:

  • http
  • location
  • server

The code will be something like this:

server {
    # set the max body size across the site to be 20mb
    client_max_body_size 20m;
}

Personally I would put the client_max_body_size on a location block. This means that your new max body size will not be globally set and instead set for a particular sub location of your website.

server {
    # site default is 1mb
    client_max_body_size 1m;


    location /user/profiles/upload {
        # profile images should be no more than 2m
        client_max_body_size 5m;
        # the rest of your website will still use 1m max body size
    }
}

note: Remember you will need to reload your config file before changes take affect.

also note: You only make the client_max_body_size the value you need plus a little bit. Stops people potentially sending up massively huge files in an attempt to cripple your server.

like image 136
Matt Seymour Avatar answered Oct 04 '22 02:10

Matt Seymour