Apache httpd 目录列表禁用配置(options indexes)

简介: Apache httpd服务器在缺省的情况下,开启了基于目录列表的访问,这是一个存在安全隐患的问题,因此可以关闭这个功能。

Apache httpd服务器在缺省的情况下,开启了基于目录列表的访问,这是一个存在安全隐患的问题,因此可以关闭这个功能。在Apache 2.4的版本中,不在支持使用-indexes来配置,需要注释该功能。本文对此给出演示,供大家参考。

一、缺省情况目录列表可查看示例

当前环境
[root@centos7-web ~]# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

[root@centos7-web ~]# apachectl -v
Server version: Apache/2.4.6 (CentOS)
Server built:  Nov 19 2015 21:43:13

为站点添加index.html页面
# echo "This is a apache test index page" > /var/www/html/index.html
[root@centos7-web ~]# curl http://localhost
This is a apache test index page

移除index.html
[root@centos7-web ~]# mv /var/www/html/index.html /var/www/html/index.tmp

依旧可以访问,不过此时为apache的缺省欢迎页面
这里写图片描述

移除apache欢迎页面
[root@centos7-web ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bk  
[root@centos7-web ~]# cp /usr/share/backgrounds/* /var/www/html/.

这里写图片描述

[root@centos7-web ~]# grep -Ev "^$|^#|*#" /etc/httpd/conf/httpd.conf >/etc/httpd/conf/httpd.conf.tmp
[root@centos7-web ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.1106 
[root@centos7-web ~]# mv /etc/httpd/conf/httpd.conf.tmp /etc/httpd/conf/httpd.conf
mv: overwrite ‘/etc/httpd/conf/httpd.conf’? yes

二、关闭options 中Indexes(关闭文件列表)

[root@centos7-web ~]# vim /etc/httpd/conf/httpd.conf 
 [root@centos7-web ~]# grep "Indexes" -B1 -A3 /etc/httpd/conf/httpd.conf   查看修改后的结果
<Directory "/var/www/html">
#  Options Indexes FollowSymLinks   ##注释该行
    AllowOverride None
    Require all granted
</Directory>

[root@centos7-web ~]# systemctl reload httpd    
[root@centos7-web ~]# curl http://localhost                    
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /
on this server.</p>
</body></html>

三、关闭FollowSymLinks(关闭访问符号链接文件)

[root@centos7-web ~]# ln -sv /etc/redhat-release /var/www/html/redhat-release.html
‘/var/www/html/redhat-release.html’ -> ‘/etc/redhat-release’
[root@centos7-web ~]# ls -hltr /var/www/html/redhat-release.html
lrwxrwxrwx 1 root root 19 Sep 21 16:15 /var/www/html/redhat-release.html -> /etc/redhat-release

[root@centos7-web ~]# curl http://localhost/redhat-release.html                  
CentOS Linux release 7.2.1511 (Core) 

[root@centos7-web ~]# vim /etc/httpd/conf/httpd.conf 
Options None   ##改成Options None 
[root@centos7-web ~]# systemctl reload httpd 

[root@centos7-web ~]# curl http://localhost/redhat-release.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>   ##Author : Leshami
<h1>Forbidden</h1> ## Blog : http://blog.csdn.net/leshami
<p>You don't have permission to access /redhat-release.html
on this server.</p>
</body></html>
目录
相关文章
|
1月前
|
Ubuntu Apache
apache2 ubuntu18.04 配置虚拟端口
apache2 ubuntu18.04 配置虚拟端口
|
2月前
|
运维 Linux Apache
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
Linux Apache服务详解——Apache虚拟目录与禁止显示目录列表实战
24 2
|
20天前
|
负载均衡 Ubuntu 应用服务中间件
Apache(mod_proxy)+Tomcat负载均衡配置
Apache(mod_proxy)+Tomcat负载均衡配置
|
24天前
|
缓存 负载均衡 网络安全
如何配置Apache的反向代理
如何配置Apache的反向代理
|
26天前
|
存储 Linux 数据库
ZooKeeper【搭建 01】apache-zookeeper-3.6.2 单机版安装+配置+添加到service服务+开机启动配置+验证+chkconfig配置(一篇入门zookeeper)
【4月更文挑战第8天】ZooKeeper【搭建 01】apache-zookeeper-3.6.2 单机版安装+配置+添加到service服务+开机启动配置+验证+chkconfig配置(一篇入门zookeeper)
38 0
|
1月前
|
Ubuntu Linux Apache
linux下apache2更换目录
linux下apache2更换目录
|
2月前
|
运维 Linux Apache
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
LAMP架构调优(十)——Apache禁止指定目录PHP解析与错误页面优化
200 2
|
2月前
|
Shell Linux 网络安全
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 httpd命令 使用指南
【Shell 命令集合 网络通讯 】Linux 管理Apache HTTP服务器 httpd命令 使用指南
36 0
|
2月前
|
消息中间件 API Apache
官宣|阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会
本文整理自阿里云开源大数据平台徐榜江 (雪尽),关于阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会。
1628 2
官宣|阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会
|
2月前
|
SQL Java API
官宣|Apache Flink 1.19 发布公告
Apache Flink PMC(项目管理委员)很高兴地宣布发布 Apache Flink 1.19.0。
1631 2
官宣|Apache Flink 1.19 发布公告

推荐镜像

更多