Apache 中的选项如何工作

Apache 中的选项如何工作

进入原始的 httpd.conf,我有

Options Indexes FollowSymLinks

我在 /etc/httpd/conf.d/ 中创建了一个配置文件

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

我认为更具体的规则优先于一般规则

我是不是遗漏了什么?

答案1

你基本上是正确的,但是在使用选项时忽略了一个微妙之处。

但是,首先,不要仅仅将它们粘贴在 NameVirtualHost 容器中,而是使用目录语句...

您说得对,最具体的那些适用,但是,如果选项语句包含选项列表,其中每个人以 + 或 - 为前缀,则选项将与任何现有选项合并......

这意味着

Options Indexes FollowSymLinks

合并至

Options -ExecCGI -Indexes

来形成

Options Indexes FollowSymLinks -ExecCGI

看看 apache 文档http://httpd.apache.org/docs/2.2/mod/core.html

具体来说,例如:

...如果第二个 Options 指令使用 + 和 - 符号:

<Directory /web/docs>
   Options Indexes FollowSymLinks
</Directory>

<Directory /web/docs/spec>
   Options +Includes -Indexes
</Directory>

然后为目录设置选项 FollowSymLinks 和 Includes /web/docs/spec

因此,Apache 在您的配置下表现出的行为是正确的。

我只需明确声明 NameVirtualHost 的选项如下:

<Directory /var/www/html/deve>
  Options +FollowSymlinks -Indexes -ExecCGI
</Directory>

相关内容