我需要只允许特定目录的目录列表:/var/www/test
。我按照这里给出的步骤 http://wiki.apache.org/httpd/DirectoryListings但是我做错了什么,因此如果我浏览 http://localhost/test
,我会收到 Forbidden 403 消息。以下是我的/etc/apache2/sites-available/test 中的内容。你能发现这个配置有什么错误吗?
<VirtualHost *:80>
DocumentRoot /var/www
<FilesMatch index.html>
deny from all
</FilesMatch>
<Directory /var/www/php/>
AllowOverride None
deny from all
</Directory>
<Directory /var/www/>
AllowOverride None
</Directory>
<Directory /var/www/test>
Options +Indexes
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
最佳答案
Order
您正在为 /var/www/test
指定是deny,allow
, 所以 Deny from all
在 /var/www
优先于 Allow from all
对于 /var/www/test
.将其切换为 allow,deny
你会得到你期望的行为。
我还强烈建议您删除 <FilesMatch index.html>
.这只会给你带来麻烦。 index.html
与自动目录索引无关;它仅在您明确创建此类文件时才会涉及,因此该指令将保持正常 index.html
曾经工作过的文件。
关于linux - 配置 Apache 以允许禁止目录列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12632552/