进入原来的httpd.conf,我有
Options Indexes FollowSymLinks
我在/etc/httpd/conf.d/中创build了一个configuration文件
NameVirtualHost 192.168.0.2:8009 <VirtualHost 192.168.0.2:8009> DocumentRoot /var/www/html/deve ServerName "deve:8009" ErrorLog /var/www/deve_errorlog CustomLog /var/www/deve_customlog common Options -ExecCGI -Indexes </VirtualHost>
我重新启动服务器,我仍然可以看到文件
http://192.168.0.2:8009/images
我认为更具体的规则覆盖了一般的规则
我在哪里错过了什么?
你基本上是正确的,但是在使用选项时错过了一个微妙之处。
但是,首先,不要将它们粘在NameVirtualHost容器中,使用Directory Statement …
你是正确的,最具体的适用,但是,如果一个选项声明包含一个选项的列表,其中每一个前缀+或 – ,然后选项是合并任何现有的选项…
意即
Options Indexes FollowSymLinks
与合并
Options -ExecCGI -Indexes
来形成
Options Indexes FollowSymLinks -ExecCGI
看看Apache文档http://httpd.apache.org/docs/2.2/mod/core.html
特别是在这个例子中:
…如果第二个选项指令使用+和 – 符号:
<Directory /web/docs> Options Indexes FollowSymLinks </Directory> <Directory /web/docs/spec> Options +Includes -Indexes </Directory>
那么为
/web/docs/spec目录设置FollowSymLinks和Includes选项。
因此,Apache正在展示你的configuration的行为是正确的。
我只是明确地声明NameVirtualHost的选项如下:
<Directory /var/www/html/deve> Options +FollowSymlinks -Indexes -ExecCGI </Directory>
嘿@ColtonCat,我有一个关于你的答案的问题。 为什么你认为Indexes FollowSymLinks与-ExecCGI -Indexesforms合并Indexes FollowSymLinks -ExecCGI ? 不应该是FollowSymLinks -ExecCGI 。 来自Apache文档的例子似乎是以这种方式工作的,即/web/docs/spec 中的 Indexes 删除 /web/docs 中的 Indexes 。 我在这里错过了什么吗? 你认为实际的罪魁祸首是Options应该放入“目录”指令? (对不起,我不得不写这个答案,因为我还不能发表评论)