Apache Options - 索引配置不起作用

tec*_*ark 7 apache httpd.conf

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

<VirtualHost ipaddr:80>
    ServerAdmin webmaster@site.com
    ServerName imgs.site.com
    ServerAlias www.imgs.site.com
    DocumentRoot /usr/tomcat/webapps/site/images

    <Directory /usr/tomcat/webapps/site/images>
       Options -Indexes FollowSymLinks
       AllowOverride none
    </Directory>

    CustomLog logs/imgs.site.com_access_log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
    ErrorLog logs/imgs.site.com_error_log 
</VirtualHost>

<VirtualHost ipaddr:80>
    ServerAdmin webmaster@site.com
    ServerName imgs.site.com
    ServerAlias www.imgs.site.com imgs.site.net
    DocumentRoot /usr/tomcat/webapps/site/images

    <Directory /usr/tomcat/webapps/site/images>
       Options -Indexes FollowSymLinks
       AllowOverride none
    </Directory>

    CustomLog logs/imgs.site.com_access_log "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
    ErrorLog logs/imgs.site.com_error_log
</VirtualHost>

hud*_*jev 8

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

DocumentRoot /usr/tomcat/webapps/site

<Directory ~ "/.*/">
    Options -Indexes
</Directory>
Run Code Online (Sandbox Code Playgroud)

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

  • >我认为`Directory`指令中的路径被附加到`DocumentRoot` <<看起来我错了:"`Directory-path`要么是目录的*full path*,要么是使用Unix的通配符字符串shell样式匹配"(http://httpd.apache.org/docs/2.2/mod/core.html#directory).所以,我的例子只是因为它匹配*主机内的每个目录*. (2认同)

MrW*_*ite 5

Options -Indexes FollowSymLinks
Run Code Online (Sandbox Code Playgroud)

从Apache 2.0和Apache 2.2文档中

警告
Options+或-与不带有+或- 混合使用是无效的语法,并且可能会导致意外结果。

Apache 2.4中,这将是...

...在服务器启动期间通过语法检查被中止而被拒绝。

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

Options -Indexes +FollowSymLinks
Run Code Online (Sandbox Code Playgroud)


Zed*_*Zed 2

一个快速的解决方法是将index.html具有任意内容的文件放入目录中。索引将显示该文件的内容而不是目录列表。