Apache和每个用户的WebDAV DocumentRoot

我有一个WebDAV用户设置,目前从我的MySQL数据库获取用户名和密码。 我给用户select使用WebDAV进行大file upload(这是为我正在开发的文件共享服务),但我已经达到了我似乎无法弄清的一个小问题。

首先 – 如何让每个用户拥有自己的WebDAV根目录,以便他们不能查看其他用户的文件? 我已经运行了一个cronjob来检查任何启用WebDAV的用户,并自动创build具有适当权限的目录。 我只需要一些告诉Apache这个方法。

感谢您的帮助,我真的很感激。

我也知道我可以每分钟运行一个cronjob来生成一个apacheconfiguration并重新加载apacheconfiguration,但是这只是有点太多的开销,我想要更多的灵活性。

Apache的configuration不如Nginx灵活,所以你可以这样做:

Alias /dav /path/to/dav/store/$REMOTE_USER 

但是,您可以在重写规则中使用REMOTE_USER ,如下所示:

 RewriteEngine On RewriteRule ^/dav(.*)$ /__davinternal/%{LA-U:REMOTE_USER} [PT] 

然后把你所有的authentication/戴维斯的可爱进入一个<Location /__davinternal>和鲍勃的阿姨的住在情人。

如果你的文件系统中的所有用户都有一致的位置(比如/path/to/dav/store/<username> ) 如果你在文件系统中分散了用户文件夹(在MySQL中有映射),你仍然可以映射你的用户位置,但是你必须使用RewriteMap

 RewriteMap davdirs txt:/path/to/user/dir/map.txt RewriteRule /^dav(.*)$ /__davinternal/${davdirs:%{LA-U:REMOTE_USER}} 

你可以直接从MySQL(通过外部脚本)做一个RewriteMap,但是我会尝试让我的应用程序在更新映射信息时更新一个dbm文件,而不是使用dbm映射 – 性能要好得多,把你的数据库打入地面。

我没有在这个答案中涉及到这些设置的安全含义,部分原因是我不完全确定我自己,也不知道你的确切安全策略可能是什么。

据我所知(2-3年前),你需要添加一个每个用户/目录configuration。

 # cat /etc/apache2/conf.d/dav_store.conf # First you need to say that a share under location X will be a webdav share: Alias /store /home/davfs/storage/ <Directory /home/davfs/storage/> DAV On AuthType Basic AuthName "sample" Auth_MySQL On Auth_MySQL_Authoritative On Auth_MySQL_Host localhost Auth_MySQL_User _admin Auth_MySQL_Password 123 Auth_MySQL_DB dav Auth_MySQL_Password_Table auth_user Auth_MySQL_Username_Field username Auth_MySQL_Password_Field password Auth_MySQL_Empty_Passwords Off Auth_MySQL_Encryption_Types Django #This was custom. #AuthMySQLUserCondition = "is_active = 1" # non root users cannot view this directory Options -Indexes -MultiViews AllowOverride None require user root; </Directory> <Directory /home/davfs/storage/*/> DAV On require user root; </Directory> Include /home/davfs/etc/conf.d/*.dvu 

并且每个用户configuration文件将用户locking到一个目录。 这是一个示例

 <Directory /home/davfs/storage/lm/lmwangi/> # We need this in subdirs.. otherwise error messages such as # "DAV Off" cannot be used to turn off a subtree of a DAV-enabled location. # will fill up your log DAV On require user lmwangi </Directory> 

这就是这一切。 我认为你必须在每次configuration更改时重新加载Apache。 如果这些任务可以使用Apache模块来完成,那将是非常棒的…(没有更多的crons来生成configuration,没有更多的重载等)