当前位置:首页 > PHP教程 > Apach > 列表

Apache设置禁止访问网站目录,目录列表显示文件

发布:smiling 来源: PHP粉丝网  添加日期:2014-09-20 14:56:00 浏览: 评论:0 

默认apache在当前目录下没有index.html入口就会显示目录,让目录暴露在外面是非常危险的事,如下操作禁止apache显示目录,希望文章对各位有帮助.

进入apache的配置文件 httpd.conf 找到如下代码:

Options Indexes FollowSymLinks 修改为:Options FollowSymLinks

其实就是将Indexes去掉,Indexes表示若当前目录没有index.html就会显示目录结构.

1. 禁止访问某些文件/目录,增加Files选项来控制,比如要不允许访问 .inc 扩展名的文件,保护php类库,代码如下:

  1. <Files ~ ".inc$"> 
  2. Order allow,deny 
  3. Deny from all 
  4. </Files> 
 

禁止访问某些指定的目录,可以用 <DirectoryMatch> 来进行正则匹配,代码如下:

  1. <Directory ~ "^/var/www/(.+/)*[0-9]{3}"> 
  2. Order allow,deny 
  3. Deny from all 
  4. </Directory> 

通过文件匹配来进行禁止,比如禁止所有针对图片的访问,代码如下:

  1. <FilesMatch .(?i:gif|jpe?g|png)$> 
  2. Order allow,deny 
  3. Deny from all 
  4. </FilesMatch> 

针对URL相对路径的禁止访问,代码如下:

  1. <Location /dir/> 
  2. Order allow,deny 
  3. Deny from all 
  4. </Location> 

配置示例,代码如下:

  1. <Directory "E:/Program Files/Apache Software Foundation/Apache2.2/htdocs"> 
  2. # 
  3. # Possible values for the Options directive are "None", "All", 
  4. # or any combination of: 
  5. # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 
  6. # 
  7. # Note that "MultiViews" must be named *explicitly* --- "Options All" 
  8. # doesn't give it to you. 
  9. # 
  10. # The Options directive is both complicated and important. Please see 
  11. # http://httpd.apache.org/docs/2.2/mod/core.html#options 
  12. # for more information. 
  13. # 就是这一行,只去掉indexes也可 
  14. #Options Indexes FollowSymLinks 
  15. Options FollowSymLinks 
  16. # 
  17. # AllowOverride controls what directives may be placed in .htaccess files. 
  18. # It can be "All", "None", or any combination of the keywords: 
  19. # Options FileInfo AuthConfig Limit 
  20. # 
  21. AllowOverride None 
  22. # 
  23. # Controls who can get stuff from this server. 
  24. # 
  25. Order allow,deny 
  26. Allow from all 
  27. </Directory> 
  28. //开源代码phpfensi.com 

建议默认情况下,设置APACHE禁止用户浏览目录内容.

Tags: Apache禁止访问 Apache禁止目录

分享到: