Apache2:如何限制对DocumentRoot中文件的访问

我写了这个configuration限制访问/var/www/news.html

 <VirtualHost *:80> ServerName example.com DocumentRoot /var/www/ <Directory /var/www/> Order deny,allow Allow from all Options FollowSymLinks </Directory> <Files /var/www/news.hmtl> Order allow,deny Deny from all </Files> </VirtualHost> 

但它仍然打开example.com/news.html 。 我已经通过显式限制访问URL example.com/news.html来解决这个问题:

 <Location /news.html> Order allow,deny Deny from all </Location> 

当将URLparsing为path相对的DocumentRoot时,似乎所有的<Directory><Files>规则都被一些隐含的<Location>所覆盖。 这是否是真的,我应该考虑DocumentRoot喜欢关于一个公众可见的地方?

Files指令不会占用path – 像这样改变你的文件块。

 <Files news.hmtl> Order allow,deny Deny from all </Files> 

上面的工作,但可能不完全是你想要的任何和所有文件命名news.html在整个虚拟主机文件系统将被阻止。 您可以通过将其包含在Directory指令中来限制Files指令的范围

 <Directory /var/www/test> Order deny,allow Allow from all Options FollowSymLinks <Files news.hmtl> Order allow,deny Deny from all </Files> </Directory> 

现在,在/var/www/test目录中名为news.html的文件及其所有子目录都将被阻止。

查看Apache文档的Filesystem和Webspace部分,了解这些指令如何交互的更多信息。