限制对apache 2.4目录的访问,但允许某些文件

时间:2017-07-07 16:22:40

标签: apache configuration apache2.4

我有一个apache 2.4服务器,托管2个应用程序。其中一个可以免费访问互联网,另一个仅限于某些IP。所以在我的/etc/apache2.conf文件中我有以下内容:

<Directory /var/www/>
   Options FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

<Directory /var/other/>
   Options FollowSymLinks
   AllowOverride None
   Require ip [ip]
</Directory>

这很好用,当我尝试从/ var / other访问任何正在提供的页面时,我得到403禁止,除非我在正确的IP上。但是,我现在想在没有IP限制的情况下使/ var / other /目录中的某些页面可以自由访问。我尝试了各种组合,例如下面的嵌套&lt; Files&gt;标记以授予对特定文件的所有访问权限但似乎不起作用。

<Directory /var/www/>
   Options FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

<Directory /var/other/>
   Options FollowSymLinks
   AllowOverride None
   Require ip [ip]
   <Files "/var/other/page.php">
      Require all granted
   </Files>
</Directory>

我试过把&lt; Files&gt;在“需要ip [ip]”之前以及&lt; Directory&gt;之前和之后的标记标签但似乎也没有用。有谁知道这是否可能以及我将如何实施它?

1 个答案:

答案 0 :(得分:1)

你不应该在Files部分中有目录,只有文件名:

   <Files "page.php">
相关问题