我正在使用django-resto将我的媒体文件上传到远程服务器。但是,当我尝试上传时,它会给我django_resto.storage: Failed on create
。
并在消息下面生成日志,
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"
有人可以解释为什么我会收到这样的错误吗?
媒体服务器的设置
DEFAULT_FILE_STORAGE = 'django_resto.storage.DistributedStorage'
RESTO_MEDIA_HOSTS = ['IP:8081']
Nginx配置,
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;
}
}
答案 0 :(得分:18)
此问题将由nginxs低默认client_max_body_size
值(1MB)引起。
您需要在以下某个上下文块中将client_max_body_size <value>
设置为更高的值:
代码将是这样的:
server {
# set the max body size across the site to be 20mb
client_max_body_size 20m;
}
我个人会将client_max_body_size
放在location
块上。这意味着您的新最大体型不会全局设置,而是设置为您网站的特定子位置。
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
}
}
注意:请记住,在更改生效之前,您需要重新加载配置文件。
还请注意:您只需要client_max_body_size
所需的值加上一点点。阻止人们发送大量巨大的文件以试图削弱您的服务器。