Apache-2.2

允許 Apache 2.2 中特定 VirtualHost 的目錄查看/遍歷

  • March 23, 2016

我配置了以下虛擬主機:

<VirtualHost *:80>
   DocumentRoot /var/www/myvhost
   ServerName myv.host.com
   ServerAlias myv.host.com
   ErrorLog logs/myvhost-error_log
   CustomLog logs/myvhost-access_log combined
   ServerAdmin myv@host.com
   <Directory /var/www/myvhost>
       AllowOverride All
       Options +Indexes
   </Directory>
</VirtualHost>

從工具的角度來看,配置似乎是正確的。apachectl

但是,我無法在該虛擬主機上獲得目錄列表:

Forbidden

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

錯誤日誌顯示以下內容:

[Wed Mar 07 19:23:33 2012] [error] [client 66.6.145.214] Directory index forbidden by Options directive: /var/www/******

更新2

最近,以下內容正在進入 error.log:

[Wed Mar 07 20:16:10 2012] [error] [client 192.152.243.233] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/error/noindex.html

更新3

今天,以下內容被踢出:

[Thu Mar 08 14:05:56 2012] [error] [client 66.6.145.214] Directory index forbidden by Options directive: /var/www/<mydir>
[Thu Mar 08 14:05:56 2012] [error] [client 66.6.145.214] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/error/noindex.html
[Thu Mar 08 14:05:57 2012] [error] [client 66.6.145.214] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

這是在修改vhosts.conf文件之後:

<VirtualHost *:80>
   DocumentRoot /var/www/<mydir>
   ServerName myhost
   ServerAlias myhost
   ErrorLog logs/myhost-error_log
   CustomLog logs/myhost-access_log combined
   ServerAdmin admin@myhost
   <Directory "/var/www/<mydir>">
        Options All +Indexes +FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
   </Directory>
</VirtualHost>

什麼不見了?

更新 4

根目錄的所有子目錄都可以正確列出目錄 -只有根目錄不能。

403 表示正在查找資源。檢查 apache 是否r-x對文件根目錄及其上方的所有目錄以及r--其中的文件具有某種級別的權限。

嘗試將您的目錄指令更改為

<Directory /var/www/myvhost>
   AllowOverride All
   Options +Indexes
   Order allow,deny 
   Allow from all
</Directory>

我今天遇到了類似的問題,我看到了上面顯示的錯誤:

[Wed Oct 17 14:19:08 2012] [error] [client 123.66.66.22] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/mysite/

混合帶有和不帶有 +/- 的選項是有問題的,請注意關於 options 的 apache 文件

將帶有 + 或 - 的選項與沒有的混合是無效的語法,並且將在伺服器啟動期間被帶有中止的語法檢查拒絕。

此外,有效地使用不帶 +/- 的指令的效果也會刪除之前為該目錄設置的所有其他指令。

我使用了沒有 + 的索引,並且出現了上面複製的錯誤。

既然您說您沒有使用任何 .htaccess 文件,為什麼不將 Directory 指令更改為:

<Directory /var/www/myvhost>
   AllowOverride None
   Options +Indexes
   Order allow,deny
   Allow from all
</Directory>

引用自:https://serverfault.com/questions/367346