Apache2 配置禁止显示目录列表

来源:互联网 发布:人工智能ai 下载 编辑:程序博客网 时间:2024/05/21 17:07
一、默认情况,如果apache指定的目录没有下面项配置的“index.php index.html index.htm”文件之一,则appache会显示目录及目录下的所有文件: 
<IfModule dir_module>     DirectoryIndex index.php index.html index.htm </IfModule> 


二、在apache2里,所有的配置都可以写到/etc/apache2/httpd.conf(默认里面是空的), 但是在它的站点配置文件/etc/apache2/sites-available/* (例如default)文件里面,可以单独针对某个单独的域名来配置规则,在里面找到目录配置:
 <Directory />      Options Indexes FollowSymLinks      AllowOverride None </Directory> <Directory /var/www/>     Options Indexes FollowSymLinks MultiViews     AllowOverride None     Order allow,deny     allow from all </Directory>


修改Options项,去掉“Indexes”,或者改成“-Indexes”即可(索引),即改为:

 <Directory />      Options FollowSymLinks      AllowOverride None </Directory> <Directory /var/www/>     Options FollowSymLinks MultiViews     AllowOverride None     Order allow,deny     allow from all </Directory>
或是

 <Directory />      Options -Indexes FollowSymLinks      AllowOverride None </Directory> <Directory /var/www/>     Options -Indexes FollowSymLinks MultiViews     AllowOverride None     Order allow,deny     allow from all </Directory>

修改完配置,重新载入apache2配置或者重启apache2即可:
sudo servcie apache2 reload //或者是service httpd restart

注意:以上针对有权限修改网站服务器的同学,如果你的是虚拟主机,请使用“.htaccess”文件实现。

也可以在目录下添加一个空白html文件,比如在/srv/httpd/ 目录下新建一个空白index.html

<!doctype html><html><head><meta charset="utf-8"><title></title></head><body></body></html>
这样的话访问域名时就会访问这个空白index.html文件

0 0
原创粉丝点击