php Apache 2.4,在浏览器中启用文件夹视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10789719/
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
Apache 2.4, enabling folder view in browser
提问by Tony Arnold
Using Apache 2.4 64 bit VC10 build on my Win 7 machine from Apache Lounge, how do I enable folder file view? I just want to see what files are in every folder that does not have a index file in that folder.
在 Apache Lounge 的 Win 7 机器上使用 Apache 2.4 64 位 VC10 构建,如何启用文件夹文件视图?我只想查看每个文件夹中没有索引文件的文件。
This is for dev purposes only. I have tried using Options Indexes / All options and restarted my server a few times. All I get is 403 Forbidden.
这仅用于开发目的。我试过使用选项索引/所有选项并重新启动我的服务器几次。我得到的只是 403 Forbidden。
回答by Brady
For Apache 2.4, if you have enabled Directory Indexessuch as index.html or index.php you must first disable that before you can get folders and files to show in a web browser.
对于 Apache 2.4,如果您启用了诸如 index.html 或 index.php 之类的目录索引,则必须先禁用它,然后才能在 Web 浏览器中显示文件夹和文件。
<Directory "/vhost/www/htdocs/path/to/folder">
DirectoryIndex disabled
Options Indexes
</Directory>
回答by Kyle Coots
The directive in Apache has changed from version 2.2 to 2.4 and up.
Apache 中的指令已从 2.2 版更改为 2.4 版及更高版本。
I am running version 2.4.7 and a basic vhost file looks like this:
我正在运行 2.4.7 版,一个基本的 vhost 文件如下所示:
<VirtualHost 192.168.1.5:80>
DocumentRoot /srv/html/
ServerName some.placeoverthe.rainbow
<Directory /srv/html/>
Options Indexes ## Allows directory browsing.
Require all granted ## Allow all request
</Directory>
</VirtualHost>
Taken form the Apache website: https://httpd.apache.org/docs/2.4/upgrading.html
取自 Apache 网站:https: //httpd.apache.org/docs/2.4/upgrading.html
Here are some examples of old and new ways to do the same access control.
以下是执行相同访问控制的新旧方法的一些示例。
In this example, all requests are denied.
在本例中,所有请求都被拒绝。
2.2 configuration:
2.2 配置:
Order deny,allow
Deny from all
2.4 configuration:
2.4 配置:
Require all denied
In this example, all requests are allowed.
在此示例中,允许所有请求。
2.2 configuration:
2.2 配置:
Order allow,deny
Allow from all
2.4 configuration:
2.4 配置:
Require all granted
In the following example, all hosts in the example.org domain are allowed access; all other hosts are denied access.
在下面的例子中,example.org 域中的所有主机都被允许访问;所有其他主机都被拒绝访问。
2.2 configuration:
2.2 配置:
Order Deny,Allow
Deny from all
Allow from example.org
2.4 configuration:
2.4 配置:
Require host example.org
Directory Indexing
目录索引
Taken form the Apache website: http://httpd.apache.org/docs/2.4/mod/core.html
取自 Apache 网站:http: //httpd.apache.org/docs/2.4/mod/core.html
The Options directive controls which server features are available in a particular directory.
Options 指令控制在特定目录中哪些服务器功能可用。
option can be set to None, in which case none of the extra features are enabled, or one or more of the following:
选项可以设置为无,在这种情况下,不启用任何额外功能,或以下一项或多项:
All
全部
All options except for MultiViews.
ExecCGI
执行CGI
Execution of CGI scripts using mod_cgi is permitted.
FollowSymLinks
关注符号链接
The server will follow symbolic links in this directory. This is the default setting.
服务器将遵循此目录中的符号链接。这是默认设置。
Even though the server follows the symlink it does not change the pathname used to match against sections.
即使服务器遵循符号链接,它也不会更改用于匹配部分的路径名。
The FollowSymLinks and SymLinksIfOwnerMatch Options work only in sections or .htaccess files.
FollowSymLinks 和 SymLinksIfOwnerMatch 选项仅适用于部分或 .htaccess 文件。
Omitting this option should not be considered a security restriction, since symlink testing is subject to race conditions that make it circumventable.
省略此选项不应被视为安全限制,因为符号链接测试受竞争条件的影响,使其可以规避。
Includes
包括
Server-side includes provided by mod_include are permitted.
IncludesNOEXEC
包括NOEXEC
Server-side includes are permitted, but the #exec cmd and #exec cgi are disabled. It is still possible to #include virtual CGI scripts from ScriptAliased directories.
Indexes
索引
If a URL which maps to a directory is requested and there is no DirectoryIndex(e.g., index.html) in that directory, then mod_autoindexwill return a formatted listing of the directory.
如果请求映射到目录的 URL 并且该目录中没有 DirectoryIndex(例如index.html),则mod_autoindex将返回该目录的格式化列表。
MultiViews
多视图
Content negotiated "MultiViews" are allowed using mod_negotiation.
允许使用 mod_negotiation 协商内容“MultiViews”。
Note:This option gets ignored if set anywhere other than , as
mod_negotiation needs real resources to compare against and evaluate from.
注意:如果设置为
以外的任何地方,则此选项将被忽略,因为mod_negotiation 需要实际资源来进行比较和评估。
SymLinksIfOwnerMatch
符号链接如果所有者匹配
The server will only follow symbolic links for
which the target file or directory is owned by
the same user id as the link.
As a side note:You might want to check and make sure that the user that apache is running under has permission to read from that directory. On windows this may not be an issue but on Linux it very well can be an issue. On most Linux distros the default user is typically :
附带说明:您可能需要检查并确保运行 apache 的用户有权从该目录读取。在 Windows 上,这可能不是问题,但在 Linux 上,这可能是一个问题。在大多数 Linux 发行版中,默认用户通常是:
www-data
万维网数据
So you would need to change permissions for that directory to allow apache access if the directory is owned by someone other than the user apache runs under.
因此,如果该目录的所有者不是 apache 运行的用户,则您需要更改该目录的权限以允许 apache 访问。
回答by hakre
<Directory "/srv/www/htdocs">
Options +Indexes
################
Order allow,deny
Allow from all
</Directory>

