问题
在Web浏览器中可见的索引,其中不包含index.html或index.php文件的目录。
我无法在Scientific Linux的httpd Web服务器上进行配置,以停止显示这些索引。
无效的配置
httpd.conf虚拟主机目录指令:
Options FollowSymLinks
AllowOverride all
Require all granted
并在.htaccess中添加以下行:
Options -Indexes
目录索引仍在显示。 .htaccess设置不起作用!
.htaccess中的其他设置如何工作,那为什么不呢? 怎么了 它应该正常工作! %#$&^ $%@#!!
修复
将httpd.conf的“选项”行更改为:
Options +FollowSymLinks
并重新启动Web服务器。
从Apache的核心mod页面:([https://httpd.apache.org/docs/2.4/mod/core.html#options])
带有+或-的选项混合使用,无效的语法无效 并在服务器启动期间通过语法检查(带有 中止。
对于不包含index.html或index.php文件的目录,不再显示Voilà目录索引。
怎么办! 新皱纹
尝试进行这种目录访问时,新条目开始显示在“ error_log”中:
[Fri Aug 19 02:57:39.922872 2016] [autoindex:error] [pid 12479] [client aaa.bbb.ccc.ddd:xxxxx] AH01276: Cannot serve directory /home/mydomain.com/htdocs/dir-without-index-file/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive
该条目来自Apache模块“ autoindex”,其LogLevel为“ error”,如错误消息的[autoindex:error]所指示-格式为[module_name:loglevel]。
要停止记录这些新条目,需要将LogLevel更改为更高级别(例如'crit')以减少日志记录-仅记录更严重的错误消息。
Apache 2.4日志级别
请参阅Apache 2.4的LogLevel核心指令。
emerg,警报,暴击,错误,警告,通知,信息,调试,trace1,trace2,trace3,tracr4,trace5,trace6,trace7,trace8
列表中更深的每个级别都会记录以前任何级别的所有消息。
Apache 2.4的默认级别为“警告”。 因此,所有分类为emerg,alert,crit,error和warn的消息都将写入error_log。
停止新的error_log条目的其他修补程序
在httpd.conf的 .. Directory>部分中添加了以下行:
LogLevel crit
解决方案1
我的虚拟主机的httpd.conf .. Directory>配置:
Options +FollowSymLinks
AllowOverride all
Require all granted
LogLevel crit
并将其添加到网站.htaccess文件的根目录/home/mydomain.com/htdocs/.htaccess中:
Options -Indexes
如果您不介意“错误”级别的消息,请省略
LogLevel crit
科学版Linux-解决方案2-禁用mod_autoindex
您的Web空间中的目录不再自动索引。 .htaccess保持不变。 但是,需要访问/ etc / httpd中的httpd配置文件
编辑/etc/httpd/conf.modules.d/00-base.conf并注释以下行:
sudo apachectl restart
通过在其前面添加#,然后保存文件。
在目录/etc/httpd/conf.d中重命名(mv)
sudo apachectl restart
重新启动httpd:
sudo apachectl restart
要么
sudo apachectl restart
现在禁用了autoindex_mod。
使用ap2dismod / ap2enmod命令的Linux发行版
禁用自动索引模块输入命令
sudo a2dismod autoindex
启用自动索引模块输入
sudo a2enmod autoindex
3577

被折叠的 条评论
为什么被折叠?



