Apache 选项 - 索引配置不起作用
我需要停止网站上图像目录的目录列表。我正在为网站上的图像和 JavaScript 配置无 Cookie 域。我已经完成了 CNAME 配置并在 httpd.conf 文件中添加了以下虚拟主机配置。但是,如果我直接访问这个无 cookie 域,它会列出整个目录内容。如何解决这个问题?
<VirtualHost ipaddr:80> ServerAdmin [email protected] 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 [email protected] 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>
I need to stop directory listing of images directory on a website. I'm configuring cookieless domain for images and javascripts on a site. I have done the CNAME configuration and added below virtual hosts configuration in httpd.conf file. But, if i access this cookieless domain directly, its listing the whole directory content. how to solve this problem?
<VirtualHost ipaddr:80> ServerAdmin [email protected] 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 [email protected] 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为
Directory
指令中的路径附加到DocumentRoot
中,因此您实际上命令 Apache 不要索引/usr/tomcat/webapps/site/images/usr/ tomcat/webapps/site/images
。请尝试以下配置:这应该禁用
/usr/tomcat/webapps/site
下所有文件夹中的目录索引,例如。/usr/tomcat/webapps/site/images/
、/usr/tomcat/webapps/site/fubar/
等。I think that path in
Directory
directive is appended toDocumentRoot
, so you actually ordering Apache not to index/usr/tomcat/webapps/site/images/usr/tomcat/webapps/site/images
. Try the following configuration instead:This should disable directory indexing in all folders under
/usr/tomcat/webapps/site
, eg./usr/tomcat/webapps/site/images/
,/usr/tomcat/webapps/site/fubar/
and so on.一个快速的解决方法是将一个包含任意内容的
index.html
文件放入该目录中。索引将显示该文件的内容而不是目录列表。A quick workaround is to put an
index.html
file into the directory, with arbitrary content. Indexing will display the contents of this file instead of the directory listing.来自 Apache 2.0 和 Apache 2.2 文档:
在 Apache 2.4 中,这将是...
因此,您基本上需要在
FollowSymLinks
前面添加一个+
(或者如果您想覆盖则完全删除-Indexes
参数 em> 所有先前定义的选项)。例如:From the Apache 2.0 and Apache 2.2 docs:
In Apache 2.4 this will be...
So, you basically need a
+
in front ofFollowSymLinks
(or remove the-Indexes
argument altogether if you want to override all previously defined options). For example: