Apache 2.4:VirtualHost中的选项+索引

我无法让Apache在VirtualHost块内重新调整一个Options指令。 下面的代码片段非常简单,我可以重现错误 – 其余configuration是一个股票Deiban Apache 2.4。

<VirtualHost *:80> ServerName example DocumentRoot /home/test/ #owner www-data:www-data Options +Indexes <Location /> Require all granted </Location> </VirtualHost> 

这将会失败,403 Forbidden和相应的日志中的以下行:

 [Sun Jun 26 15:06:30.378689 2016] [autoindex:error] [pid 15899:tid 140693629712128] [client 192.168.0.155:52850] AH01276: Cannot serve directory /home/test/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive 

但是,将Options +Indexes指令放在<Location />容器中将会修复它,并自动生成索引。

我想知道为什么它必须放在<Location />里面,而不是<VirtualHost> 。 Apache 2.4文档说, Options指令可以放在下面的上下文中[1]

上下文:服务器configuration,虚拟主机,目录,.htaccess

那为什么不在VirtualHost里面工作呢?


编辑#1

apachectl -S输出

 AH00557: apache2: apr_sockaddr_info_get() failed for garnet AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message VirtualHost configuration: *:80 garnet.cat (/etc/apache2/sites-enabled/test.conf:1) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" Mutex default: dir="/var/run/apache2/" mechanism=default Mutex watchdog-callback: using_defaults Mutex proxy: using_defaults PidFile: "/var/run/apache2/apache2.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="www-data" id=33 Group: name="www-data" id=33 

关于configuration文件中其他可能的Options指令:

我找不到任何东西。 我用root@garnet:/etc/apache2# grep -P -Rni '\soptions\s' . 在configuration文件中findOptions指令的出现。 所有匹配都在注释string中或在不相关的<Directory>块中。 无论如何, VirtualHost块不会覆盖外部指定的指令吗?

这可能是一个合并问题,详情在这里: http : //httpd.apache.org/docs/current/sections.html#merging

因此,通常更具体的configuration部分行DirectoryLocation位置可以覆盖虚拟主机级别的configuration,从而可以覆盖全局级别的configuration。 但是当你仔细研究更具体的configuration块时,如何处理它们在上面的链接中描述。

这些层次在Apache中被称为上下文,熟悉这个上下文意味着什么是一个非常好的主意,呃…呃… context :-)。 更多信息在这里: http : //httpd.apache.org/docs/current/mod/directive-dict.html#Context

正如在注释中提到的那样,在全局上下文中查找可能与您的URIpath匹配的LocationLocationMatch块,或者可能与目录树中的/home/test/或其上的任何内容匹配的DirectoryDirectoryMatch