欢迎来到代码驿站!

当前位置:首页 >

Apache设置禁止访问网站目录

时间:2020-03-10 09:53:34|栏目:|点击:

Apache默认在当前目录下没有index.html入口就会显示网站根目录,让网站目录文件都暴露在外面,是一件非常危险的事,例如:数据库密码泄露,隐藏页面暴露等严重安全问题!

本文将详细介绍如何操作禁止显示apache网站根目录。

进入apache的配置文件 httpd.conf 找到:

vim /etc/httpd/conf/httpd.conf
Options Indexes FollowSymLinks

修改为:

Options FollowSymLinks

修改后结果如下:
<Directory "/var/www/html">
  #Options None
  #Options Indexes FollowSymLinks
  Options FollowSymLinks

  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

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

重启Apache服务器 /etc/init.d/httpd restart

1. 禁止访问某些文件/目录

增加Files选项来控制,比如要不允许访问 .inc 扩展名的文件,保护php类库:
<Files ~ ".inc$">
  Order allow,deny
  Deny from all
</Files>
禁止访问某些指定的目录:(可以用 <DirectoryMatch>来进行正则匹配)
<Directory ~ "^/var/www/(.+/)*[0-9]{3}">
  Order allow,deny
  Deny from all
</Directory>
通过文件匹配来进行禁止,比如禁止所有针对图片的访问:
<FilesMatch .(?i:gif|jpeg|png)$>
  Order allow,deny
  Deny from all
</FilesMatch>
针对URL相对路径的禁止访问:
<Location /dir/>
  Order allow,deny
  Deny from all
</Location>
配置示例
<Directory "E:/Program Files/Apache Software Foundation/Apache2.2/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* — "Options All"
# doesn’t give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
# 就是这一行,只去掉indexes也可
#Options Indexes FollowSymLinks
Options FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>

上一篇:Java统计一篇文章中每个字符出现的个数

栏    目:

下一篇:R语言ggplot2边框背景去除的实现

本文标题:Apache设置禁止访问网站目录

本文地址:http://www.codeinn.net/misctech/2209.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有