2015-06-18 40 views
12

在我的Apache配置我已经配置这样的虚拟主机:如何在Apache 2.4中使用DAV和DirectoryIndex?

Alias /mediamanager /storage/files/mediamanager 
<Directory /storage/files/mediamanager> 
    DirectoryIndex /mediaManagerIndex.php 
    DAV On 
    # ... And some authentication directives ... # 
</Directory> 

的想法是,有人可以通过WebDAV的客户端,也是一个简单的Web浏览器访问这些文件无论是在这种情况下,一些漂亮的目录视图由PHP脚本生成。

在Apache 2.2中效果很好,但最近我升级到了Apache 2.4,现在已经坏了。我高度怀疑自己患有this bug,这已经是2岁,并且没有修复视力。建议的解决方法:

<Limit PROPFIND> 
    DirectoryIndex never-encounterable-file-name.html 
</Limit> 

不适用于我。可能是因为我仍然想要一个目录索引。如果我删除我的DirectoryIndex完全WebDAV的作品(没有index.html或类似的文件存在于此目录中),但当然我没有能力使用我的PHP文件作为目录索引。我试图在<Limit GET>中指定我的DirectoryIndex,但这没有效果。

有没有什么办法让DAV和DirectoryIndex同时在Debian上的Apache 2.4上工作(如果有可能的话,无需更改源代码和重新编译)?

+0

这是一种无法回答你的具体问题,但另一种可能解决这个问题的方法是丢弃apache的webdav处理程序并切换到像[saber/dav](http:// saber .io /) – Evert

回答

4

对我而言,以下配置解决了这两个问题:

  • Web DAV再次工作
  • 目录索引,如果用户使用Web浏览器来访问存储库

它通过手动实现简单的重写规则,它们是为GET请求方法仅适用于该目录,索引功能。

以下代码必须放置在服务器配置或虚拟主机上下文中的apache配置文件。

# Turn off (automatic) Directory-Indexing 
DirectoryIndex disabled 

RewriteEngine On 

# Rewrite rules for the root directory 
RewriteCond "%{REQUEST_METHOD}" "(GET)" 
RewriteRule "^/$"     "/index.php" [L] 

# Rewrite rules for other sub-directories 
RewriteCond "%{REQUEST_METHOD}" "(GET)" 
# The following line checks, if the index.php file exists 
RewriteCond "%{DOCUMENT_ROOT}/$1/index.php" "-f" 
RewriteRule "^/(.*)/$"     "/$1/index.php" [L] 

不要忘了重新加载Apache!

+0

耶!辉煌!作品! – yankee

4

为了解决这个问题,请禁用WebDAV站点的目录索引。

在您的网站可用/ site.conf文件添加DirectoryIndex disabled<Directory>声明,就像这样:

<Directory /path/to/my/webdav/dir> 
        Options Indexes FollowSymLinks MultiViews 
        AllowOverride all 
        Require all granted 

        DirectoryIndex disabled 
    </Directory> 

然后,只需重新加载Apache和你将不再有这个问题:

sudo service apache2 reload 
+0

但是如果用户使用普通的旧网页浏览器访问版本库,我想拥有目录索引 – yankee

+0

是的,这很好。只需通过不同的端口配置您的WebDAV。所以端口:80仍然会定期为目录服务。但是你通过不同的端口访问WebDAV,比如说443。然后在你的配置文件中,你只能将DirectoryIndex禁用到该端口的VirutalHost。 –

+2

这将是一个可能的紧急解决方案,但它有缺陷,我需要告诉用户两个URL:一个用于WebDAV,另一个用于使用Web浏览器。 (并且这在概念上不是必要的,在Apache 2.2中证明了这一点实际上是有效的)。 – yankee

0

对我来说,答案并不完全正确......我必须将^/$和^ /(。)/ $更改为^ /?$和^ /?(。)/ $,以便它的工作...