Apache2设置是否显示目录列表
Apache2的配置文件为 /etc/apache2/apache2.conf
,在 <Directory>
部分设置目录访问权限。
一般我们需要隐藏服务器的跟目录,所以我们将配置改为
<Directory />
- Options Indexes FollowSymLinks
+ Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
- 1
- 2
- 3
- 4
- 5
- 6
假如我们需要访问部分服务器下的目录,则新设置一个 <Directory>
节点,并且在将目录设置为服务器的绝对路径,如我们需要访问服务器下的 DownLoadList
目录
<Directory /var/www/html/DownLoadList/>
Options Indexes
IndexOptions NameWidth=25 Charset=UTF-8
Allow from all
DirectoryIndex none
</Directory>
- 1
- 2
- 3
- 4
- 5
- 6
其中DirectoryIndex none
的作用是为了避免自动打开目录下的index.html
文件
make && make install
2 和tomcat成功整合后,配置apache的默认语言为中文:
vi httpd.conf里 去掉注释#
Include conf/extra/httpd-languages.conf
然后配置conf/extra/httpd-languages.conf文件
添加如下:
DefaultLanguage zh-CN
AddDefaultCharset gb2312
<directory “=”” home=”” jack”=””>
Options Indexes FollowSymlinks
Order allow,deny
Allow from all
Options Indexes FollowSymlinks
IndexOptions FancyIndexing ScanHTMLTitles NameWidth=25
IndexIgnore favicon.ico header.html footer.html images
HeaderName header.html #header.html路径相对于主目录的
ReadmeName footer.html
AddDescription “ftp安装包” vsftpd.tar.gz
IndexOrderDefault Ascending Name
AllowOverride None
Order allow,deny
Allow from all
部分指令说明:
[编辑]
二、建立header.html和footer.html
可以在这里加入个性化内容,图片、FLASH、表格等等,随意啦!
options -indexes
(此时直接访问目录403 Forbidden)
Apache默认显示文件列表.
可以进一步控制文件列表显示模式:
这里有许多配置
在返回的文件列表信息顶部插入的Html文件.可以使用绝对或相对路径.不过仍然
指定的文件在Apache里设定的MIME类型必须为 text/*
默认的文件是header.html
附加在文件列表尾部的HTML文件.用法同 HeaderName Filename的语法
默认的文件是当前目录下 footer.html
IndexIgnore *.jpg *.ico .htaccess php.ini
在返回文件列表中屏蔽特定文件.如果设置为 IndexIgnore * ,那么实际上返回
IndexOrderDefault Ascending|Descending Name|Date|Size|Description
文件列表排序方式
设置目录列表中文件、文件夹的描述
通常的header.html 和 footer.html格式:
footer.html |
……
即把文件列表嵌套.在 表格里
<directory “=”” home=”” jack”=””>
Options Indexes FollowSymlinks
IndexOptions FancyIndexing ScanHTMLTitles HTMLTable NameWidth=125 DescriptionWidth=256 VersionSort FoldersFirst
IndexIgnore favicon.ico header.html footer.html images
HeaderName /conf/extra/header.html
ReadmeName /conf/extra/footer.html
IndexOptions Charset=GB2312
IndexOrderDefault Descending Name
AllowOverride None
Order allow,deny
Allow from all
实例:
Apache2禁止显示目录列表的设置方法
一、默认情况,如果apache指定的目录没有配置“index.php index.html index.htm”文件之一,则appache会显示目录及目录下的所有文件:
DirectoryIndex index.php index.html index.htm
</IfModule>
二、在apache2中,所有配置都可以写到/etc/apache2/httpd.conf(默认里面是空的), 但在站点配置文件/etc/apache2/sites-available/* (例如default)文件中。
可以单独针对某个单独的域名来配置规则,在其中找到目录配置:
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
修改Options项,去掉“Indexes”,或改成“-Indexes”即可(索引)。
修改完配置,重新载入apache2配置或重启apache2:
#sudo /etc/init.d/apache2 restart
重启
service apache2 restart
重启Apache服务才会生效