apache 如何禁用目录浏览?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2530372/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:58:01  来源:igfitidea点击:

How do I disable directory browsing?

apache.htaccess

提问by arthurprs

I want to disable directory browsing of /galerias folder and all subdirectories

我想禁用 /galerias 文件夹和所有子目录的目录浏览

Index of /galerias/409

* Parent Directory
* i1269372986681.jpg
* i1269372986682.jpg
* i1269372988680.jpg

/galerias/409 的索引

* Parent Directory
* i1269372986681.jpg
* i1269372986682.jpg
* i1269372988680.jpg

回答by stimpie

Create an .htaccess file containing the following line:

创建一个包含以下行的 .htaccess 文件:

Options -Indexes

That is one option. Another option is editing your apache configuration file.

那是一种选择。另一种选择是编辑您的 apache 配置文件。

In order to do so, you first need to open it with the command:

为此,您首先需要使用以下命令打开它:

vim /etc/httpd/conf/httpd.conf

Then find the line: Options Indexes FollowSymLinks

然后找到这一行:Options Indexes FollowSymLinks

Change that line to: Options FollowSymLinks

将该行更改为:Options FollowSymLinks

Lastly save and exit the file, and restart apache server with this command:

最后保存并退出文件,并使用以下命令重新启动 apache 服务器:

sudo service httpd restart

(You have a guide with screenshots here.)

(你有截图的指南在这里。)

回答by Dung

The best way to do this is disable it with webserver apache2. In my Ubuntu 14.X - open /etc/apache2/apache2.confchange from

最好的方法是使用 webserver apache2 禁用它。在我的 Ubuntu 14.X 中 -/etc/apache2/apache2.conf

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

to

<Directory /var/www/>
        Options FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

then restart apache by:

然后通过以下方式重新启动apache:

sudo service apache2 reload

This will disable directory listing from all folder that apache2 serves.

这将禁用 apache2 服务的所有文件夹的目录列表。

回答by doctorlai

Apart from the aformentioned two methods (edit /etc/apache2/apache2.confor add Options -Indexesin .htaccess file), here is another one

除了上述两种方法(编辑/etc/apache2/apache2.conf或在 .htaccess 文件中添加Options -Indexes),这里还有一种

a2dismod autoindex

Restart the apache2 server afterwards

之后重启apache2服务器

sudo service apache2 restart

回答by álvaro González

Edit/Create an .htaccessfile inside /galeriaswith this:

.htaccess在里面编辑/创建一个文件/galerias

Options -Indexes

Directory browsing is provided by the mod_autoindexmodule.

目录浏览由mod_autoindex模块提供。

回答by Martin J.H.

You can place an empty file called index.htmlinto each directory that you don't want listed. This has several advantages:

您可以将一个空文件调用index.html到您不想列出的每个目录中。这有几个优点:

  • It (usually) requires zero configuration on the server.
  • It will keep working, even if the server administrator decides to use "AllowOverride None" in the the server configuration. (If you use .htaccessfiles, this can lead to lots of "Error 500 - internal server error" messages for your users!).
  • It also allows you to move your files from one server to the next, again without having to mess with the apache configuration.
  • 它(通常)需要在服务器上进行零配置。
  • 即使服务器管理员决定在服务器配置中使用“AllowOverride None”,它也会继续工作。(如果您使用.htaccess文件,这可能会为您的用户带来大量“错误 500 - 内部服务器错误”消息!)。
  • 它还允许您将文件从一台服务器移动到另一台服务器,而不必再弄乱 apache 配置。

Theoretically, the autoindexing might be triggered by a different file (this is controlled by the DirectoryIndexoption), but I have yet to encounter this in the real world.

理论上,自动索引可能由不同的文件触发(这由DirectoryIndex选项控制),但我在现实世界中还没有遇到过这种情况。

回答by Sarvar Nishonboev

One of the important thing is on setting a secure apache web server is to disable directory browsing. By default apache comes with this feature enabled but it is always a good idea to get it disabled unless you really need it. Open httpd.conf file in apache folder and find the line that looks as follows:

重要的事情之一是设置安全的 apache 网络服务器是禁用目录浏览。默认情况下,apache 启用了此功能,但除非您确实需要,否则禁用它总是一个好主意。打开 apache 文件夹中的 httpd.conf 文件,找到如下所示的行:

Options Includes Indexes FollowSymLinks MultiViews

then remove word Indexes and save the file. Restart apache. That's it

然后删除单词索引并保存文件。重启阿帕奇。就是这样

回答by George

If you choose to modify your httpd.conf file to solve this and you have multiple Options directives, then you must add a - or a + before each directive. Example:

如果您选择修改 httpd.conf 文件来解决这个问题,并且您有多个 Options 指令,那么您必须在每个指令前添加 - 或 +。例子:

Options -Indexes +FollowSymLinks

选项 -Indexes +FollowSymLinks

回答by packetie

This is not an answer, just my experience:

这不是答案,只是我的经验:

On my Ubuntu 12.04 apache2, didn't find Indexesin either apache2.conf or httpd.conf, luckily I found it in sites-available/default. After removing it, now it doesn't see directory listing. May have to do it for sites-available/default-ssl.

在我的 Ubuntu 12.04 apache2 上,Indexes在 apache2.conf 或 httpd.conf 中都没有找到,幸运的是我在sites-available/default. 删除后,现在看不到目录列表。可能不得不为sites-available/default-ssl.

回答by zish

Open Your .htaccess file and enter the following code in

打开您的 .htaccess 文件并在其中输入以下代码

Options -Indexes

Make sure you hit the ENTER key (or RETURN key if you use a Mac) after entering the "Options -Indexes" words so that the file ends with a blank line.

确保在输入“Options -Indexes”字样后按 ENTER 键(如果使用 Mac 则按 RETURN 键),以便文件以空行结束。

回答by ????

Add this in your .htaccess file:

将其添加到您的 .htaccess 文件中:

Options -Indexes

If it is not work for any reason, try this within your .htaccess file:

如果由于任何原因它不起作用,请在您的 .htaccess 文件中尝试:

IndexIgnore *