9

我需要停止网站上图像目录的目录列表。我正在为网站上的图像和 javascripts 配置 cookieless 域。我已经完成了 CNAME 配置,并在 httpd.conf 文件中添加了虚拟主机配置。但是,如果我直接访问这个无 cookie 域,它会列出整个目录内容。如何解决这个问题呢?

<虚拟主机 ipaddr:80>
    ServerAdmin webmaster@site.com
    服务器名称 imgs.site.com
    服务器别名 www.imgs.site.com
    DocumentRoot /usr/tomcat/webapps/site/images

    <目录/usr/tomcat/webapps/site/images>
       选项 - 索引 FollowSymLinks
       允许覆盖无
    </目录>

    CustomLog 日志/imgs.site.com_access_log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
    错误日志日志/imgs.site.com_error_log
</虚拟主机>

<虚拟主机 ipaddr:80>
    ServerAdmin webmaster@site.com
    服务器名称 imgs.site.com
    服务器别名 www.imgs.site.com imgs.site.net
    DocumentRoot /usr/tomcat/webapps/site/images

    <目录/usr/tomcat/webapps/site/images>
       选项 - 索引 FollowSymLinks
       允许覆盖无
    </目录>

    CustomLog 日志/imgs.site.com_access_log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
    错误日志日志/imgs.site.com_error_log
</虚拟主机>
4

3 回答 3

9

我认为Directory指令中的路径被附加到DocumentRoot,所以你实际上命令 Apache 不要索引/usr/tomcat/webapps/site/images/usr/tomcat/webapps/site/images。请尝试以下配置:

DocumentRoot /usr/tomcat/webapps/site

<Directory ~ "/.*/">
    Options -Indexes
</Directory>

这应该禁用所有文件夹中的目录索引/usr/tomcat/webapps/site,例如。/usr/tomcat/webapps/site/images//usr/tomcat/webapps/site/fubar/等等。

于 2010-10-15T12:35:14.913 回答
9
Options -Indexes FollowSymLinks

来自 Apache 2.0 和Apache 2.2 文档

警告
将 + 或 - 与那些没有的 混合Options是无效的语法,并且可能会导致意外结果。

Apache 2.4中,这将是...

...在服务器启动期间被带有中止的语法检查拒绝。

因此,您基本上需要 a+在前面(如果您想覆盖所有先前定义的选项FollowSymLinks,则完全删除参数)。例如:-Indexes

Options -Indexes +FollowSymLinks
于 2016-10-17T11:58:25.267 回答
1

一种快速的解决方法是将index.html文件放入目录中,其中包含任意内容。索引将显示此文件的内容而不是目录列表。

于 2010-01-01T11:49:03.673 回答