在Nginx上传模块中使用Hash有什么用?

时间:2013-01-02 08:08:23

标签: hash upload nginx

我已经使用Nginx Upload正常使用Python(Tornado)。我将上传文件的路径保存在数据库中。

但是,我想知道为什么上传模块必须拆分上传并将它们放入10个不同的文件夹/var/www/.../uploads/0,1,2,3,4,5...9?下面的评论说文件是经过散列的,模块是做什么以及为什么这样做?

  # Store files to this directory
  # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
  upload_store /var/www/...uploads 1;

1 个答案:

答案 0 :(得分:2)

# filesystem location where we store uploads
#
# The second argument is the level of "hashing" that nginx will perform
# on the filenames before storing them to the filesystem. I can't find
# any documentation online, so as an example, say we were using this
# configuration:
#
#   upload_store /tmp/uploads 2 1;
#
# A file named '43829042' would be written to this path:
#
#   /tmp/uploads/42/0/43829042
#
# I hope that's clear enough. The argument is required and must be
# greater than 0. You can see the implementation here:
#
#  http://lxr.evanmiller.org/http/source/core/ngx_file.c#L118

来源:http://bclennox.com/extremely-large-file-uploads-with-nginx-passenger-rails-and-jquery