【问题标题】:Do Apache2 VirtualHost <Directory> directives cascade?Apache2 VirtualHost <Directory> 指令是否级联?
【发布时间】:2019-07-16 20:49:08
【问题描述】:

我觉得这个问题之前一定有人问过,但我找不到任何东西。

如果我有一个带有两个独立 &lt;Directory&gt; 指令的简单 VirtualHost:

<VirtualHost *:80>
    ...
    <Directory /var/www>
        Require all granted
        Options -Indexes
    </Directory>

    <Directory /var/www/api> # does the order matter?
        Require local
        Options -Indexes # is this redundant?
    </Directory>
    ...
</VirtualHost>

我的问题是:

  • 指令的顺序重要吗?如果/var/www/api 指令先出现会怎样?
  • 第二个Options -Indexes 是多余的吗?
  • 因为/var/www/api/var/www 的子目录,所以设置级联?

【问题讨论】:

  • 您为什么不简单地尝试一下呢?您投入几分钟的问题。
  • 你至少读过documentation吗? If multiple (non-regular expression) &lt;Directory&gt; sections match the directory (or one of its parents) containing a document, then the directives are applied in the order of shortest match first, interspersed with the directives from the .htaccess files. For example…Another explanation 在文档中。

标签: .htaccess http server virtualhost apache2.4


【解决方案1】:

查看section mergingDirectory directive 的官方文档(感谢@emix)

  • 是的,第二个Options -Indexes 是多余的,因为/var/wwwOptions -Indexes 设置是继承的。
    • 可以覆盖继承的设置,例如/var/www/apiOptions +Indexes 规则将显示索引。
  • 指令的顺序似乎无关紧要。规则似乎是按目录结构级联的,而不是指令本身的顺序。
  • 是的,/var/www 的设置是级联的,因为/var/www/api 是一个子目录。

【讨论】:

    猜你喜欢
    • 2021-10-16
    • 2018-06-01
    • 1970-01-01
    • 2010-10-15
    • 2010-12-03
    • 2021-05-06
    • 2014-08-18
    • 2013-07-29
    • 1970-01-01
    相关资源
    最近更新 更多