apache(禁止访问目录)与 设置默认入口文件

tech2022-07-05  168

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

例如,访问米扑网站根目录: https://mimvp.com    会列出根目录

 

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

 

1、设置默认入口文件的方法:

       打开apache的conf目录,找到httpd.conf文件,打开这个文件,搜索dir_module,找到以下截图修改位置进行修改,注意重启apache服务器,修改位置才会生效!

        

 

2、apache启动目录与禁止目录的方法:

  打开apache的conf目录,找到httpd.conf文件,打开这个文件,搜索DocumentRoot,找到以下截图修改位置进行修改,启用加Indexes,关闭是不加Indexes.注意重启apache服务器,修改位置才会生效!

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

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

 

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

增加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>

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

 

 

 

 

 

 

最新回复(0)