php 选项指令禁止的目录索引
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5301776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Directory index forbidden by Options directive
提问by logic-unit
I'm using the dompdf plugin for codeigniter: http://codeigniter.com/wiki/PDF_generation_using_dompdf/
我正在为 codeigniter 使用 dompdf 插件:http: //codeigniter.com/wiki/PDF_generation_using_dompdf/
to generate pdfs from a form. This works on localhost, but on the live server I get this in the error log:
从表单生成pdf。这适用于本地主机,但在实时服务器上,我在错误日志中得到了这个:
Directory index forbidden by Options directive: /var/www/vhosts/domain.co.uk/httpdocs/mm/userdata/account1/invoices/
Any idea what this means? I've searched for answers, and found a few that suggest editing the httpd.conf, however I don't have access to this.
知道这是什么意思吗?我搜索了答案,发现了一些建议编辑 httpd.conf 的答案,但是我无权访问它。
I've also tried adding a blank index.html file to the root and document directory (as also suggested elsewhere, but to no avail).
我还尝试将一个空白的 index.html 文件添加到根目录和文档目录中(正如其他地方所建议的,但无济于事)。
Any help greatly appreciated.
非常感谢任何帮助。
Thanks!
谢谢!
回答by Michael Berkowski
Either the main httpd.conf
or the .htaccess
file in this directory or a nearby parent directory probably includes:
无论是主httpd.conf
或.htaccess
此目录中的文件或附近的父目录可能包括:
Options -Indexes
Your host may have to set it to +Indexes
if you don't have access in .htaccess
and want to list & browse the directory contents, absent a default index.html, index.php
, etc. If the directory should not have a default file and you don't enable Indexes
, you may only directly target the filenames of contents within it.
您的主机可能将其设置为+Indexes
,如果你不具备访问.htaccess
,并希望清单及浏览目录内容,缺席默认index.html, index.php
,等等。如果目录不应该有一个默认的文件,并没有启用Indexes
,你可能仅直接针对其中内容的文件名。
The Indexes
option is commonly disabled by default on many Apache installations.
Indexes
在许多 Apache 安装中,该选项通常默认禁用。
Full details are available in the Apache core documentation on Options
Apache 核心文档中提供了完整的详细信息Options
回答by Marc B
It means there's no default document in that directory (index.html, index.php, etc...). On most webservers, that would mean it would show a listing of the directory's contents. But showing that directory is forbidden by server configuration (Options -Indexes
)
这意味着该目录中没有默认文档(index.html、index.php 等...)。在大多数网络服务器上,这意味着它将显示目录内容的列表。但显示该目录被服务器配置禁止 ( Options -Indexes
)
回答by kaosengr
The Problem
问题
Indexes visible in a web browser for directories that do not contain an index.html or index.php file.
对于不包含 index.html 或 index.php 文件的目录,在 Web 浏览器中可见的索引。
I had a lot of trouble with the configuration on Scientific Linux's httpd web server to stop showing these indexes.
我在 Scientific Linux 的 httpd web 服务器上的配置遇到了很多麻烦,无法停止显示这些索引。
The Configuration that did not work
无效的配置
httpd.conf virtual host directory directives:
httpd.conf 虚拟主机目录指令:
<Directory /home/mydomain.com/htdocs>
Options FollowSymLinks
AllowOverride all
Require all granted
</Directory>
and the addition of the following line to .htaccess:
并将以下行添加到 .htaccess 中:
Options -Indexes
Directory indexes were still showing up. .htaccess settings weren't working!
目录索引仍然出现。.htaccess 设置不起作用!
How could that be, other settings in .htaccess were working, so why not this one? What's going? It should be working! %#$&^$%@# !!
怎么可能,.htaccess 中的其他设置都在工作,那么为什么不是这个呢?怎么回事?它应该工作!%#$&^$%@#!!
The Fix
修复
Change httpd.conf's Options line to:
将 httpd.conf 的选项行更改为:
Options +FollowSymLinks
and restart the webserver.
并重新启动网络服务器。
From Apache's core mod page: ( https://httpd.apache.org/docs/2.4/mod/core.html#options)
Mixing Options with a + or - with those without is not valid syntax and will be rejected during server startup by the syntax check with an abort.
来自 Apache 的核心模组页面:(https://httpd.apache.org/docs/2.4/mod/core.html#options)
将带有 + 或 - 的选项与那些没有的混合是无效的语法,并且会在服务器启动期间通过带有中止的语法检查而被拒绝。
Voilà directory indexes were no longer showing up for directories that did not contain an index.html or index.php file.
Voilà 目录索引不再显示不包含 index.html 或 index.php 文件的目录。
Now What! A New Wrinkle
怎么办!新的皱纹
New entries started to show up in the 'error_log' when such a directory access was attempted:
尝试进行此类目录访问时,“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
This entry is from the Apache module 'autoindex' with a LogLevel of 'error' as indicated by [autoindex:error] of the error message---the format is [module_name:loglevel].
此条目来自 Apache 模块 'autoindex',其 LogLevel 为 'error',如错误消息的 [autoindex:error] 所示---格式为 [module_name:loglevel]。
To stop these new entries from being logged, the LogLevel needs to be changed to a higher level (e.g. 'crit') to log fewer---only more serious error messages.
要停止记录这些新条目,需要将 LogLevel 更改为更高级别(例如“crit”)以记录更少——仅记录更严重的错误消息。
Apache 2.4 LogLevels
Apache 2.4 日志级别
See Apache 2.4's core directives for LogLevel.
请参阅 Apache 2.4 的LogLevel核心指令。
emerg, alert, crit, error, warn, notice, info, debug, trace1, trace2, trace3, tracr4, trace5, trace6, trace7, trace8
紧急、警报、暴击、错误、警告、通知、信息、调试、trace1、trace2、trace3、tracr4、trace5、trace6、trace7、trace8
Each level deeper into the list logs all the messages of any previous level(s).
列表中更深的每个级别都会记录任何先前级别的所有消息。
Apache 2.4's default level is 'warn'. Therefore, all messages classified as emerg, alert, crit, error, and warn are written to error_log.
Apache 2.4 的默认级别是“警告”。因此,所有分类为emerg、alert、crit、error 和warn 的消息都会写入error_log。
Additional Fix to Stop New error_log Entries
停止新的 error_log 条目的附加修复
Added the following line inside the <Directory>..</Directory> section of httpd.conf:
在 httpd.conf 的 <Directory>..</Directory> 部分中添加了以下行:
LogLevel crit
The Solution 1
解决方案 1
My virtual host's httpd.conf <Directory>..</Directory> configuration:
我的虚拟主机的 httpd.conf <Directory>..</Directory> 配置:
<Directory /home/mydomain.com/htdocs>
Options +FollowSymLinks
AllowOverride all
Require all granted
LogLevel crit
</Directory>
and adding to /home/mydomain.com/htdocs/.htaccess, the root directory of your website's .htaccess file:
并加入到/ home / mydomain.com/htdocs/.htaccess,您的网站的.htaccess文件的根目录下:
Options -Indexes
If you don't mind the 'error' level messages, omit
如果您不介意“错误”级别的消息,请省略
LogLevel crit
Scientific Linux - Solution 2 - Disables mod_autoindex
Scientific Linux - 解决方案 2 - 禁用 mod_autoindex
No more autoindex'ing of directories inside your web space. No changes to .htaccess. But, need access to the httpd configuration files in /etc/httpd
不再对您的网络空间内的目录进行自动索引。.htaccess 没有变化。但是,需要访问 /etc/httpd 中的 httpd 配置文件
Edit /etc/httpd/conf.modules.d/00-base.conf and comment the line:
LoadModule autoindex_module modules/mod_autoindex.so
by adding a # in front of it then save the file.
In the directory /etc/httpd/conf.d rename (mv)
sudo mv autoindex.conf autoindex.conf.<something_else>
Restart httpd:
sudo httpd -k restart
or
sudo apachectl restart
编辑 /etc/httpd/conf.modules.d/00-base.conf 并注释该行:
LoadModule autoindex_module modules/mod_autoindex.so
通过在它前面添加一个#然后保存文件。
在目录 /etc/httpd/conf.d 重命名(mv)
sudo mv autoindex.conf autoindex.conf.<something_else>
重启httpd:
sudo httpd -k restart
或者
sudo apachectl restart
The autoindex_mod is now disabled.
autoindex_mod 现在被禁用。
Linux distros with ap2dismod/ap2enmod Commands
带有 ap2dismod/ap2enmod 命令的 Linux 发行版
Disable autoindex module enter the command
禁用自动索引模块输入命令
sudo a2dismod autoindex
to enable autoindex module enter
启用自动索引模块输入
sudo a2enmod autoindex
回答by majikman
Another issue that you might run into if you're running RHEL (I ran into it) is that there is a default welcome page configured with the httpd package that will override your settings, even if you put Options Indexes. The file is in /etc/httpd/conf.d/welcome.conf. See the following link for more info: http://wpapi.com/solved-issue-directory-index-forbidden-by-options-directive/
如果您正在运行 RHEL,您可能会遇到的另一个问题(我遇到过)是,有一个默认的欢迎页面配置了 httpd 包,该页面将覆盖您的设置,即使您放置了选项索引。该文件位于 /etc/httpd/conf.d/welcome.conf 中。有关详细信息,请参阅以下链接:http: //wpapi.com/solved-issue-directory-index-forbidden-by-options-directive/
回答by Francisco Corrales Morales
Insert this lines:
插入这一行:
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
Options +Indexes
</Directory>
In your C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf
file. I assume you are using Virtual Host for development.
在您的C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf
文件中。我假设您正在使用虚拟主机进行开发。
And then, of course, just restart Apache.
然后,当然,只需重新启动 Apache。
回答by Tommaso Lazzari
I got stuck on the same error, the problem was coming from a syntax error in a MySql statement in my code, in particular my $_session variable was missing a "'. It took hours to figure it out because on the error log the statement was misleading. Hope it helps somebody.
我遇到了同样的错误,问题出在我的代码中 MySql 语句中的语法错误,特别是我的 $_session 变量缺少一个"'。花了几个小时才弄清楚,因为在错误日志中,语句是误导。希望它可以帮助某人。
回答by Sparkplug
Adding this in conf.d fixed this issue for me.
在 conf.d 中添加它为我解决了这个问题。
Options +Indexes +FollowSymLinks
回答by LingYan Meng
In my case, it's a typo caused this issue:
就我而言,这是一个错字导致此问题:
<VirtualHost *.8080>
should be
应该
<VirtualHost *:8080>