如何为/var/www/html下的每个目录生成index.html

如何为/var/www/html下的每个目录生成index.html

/var/www/html我已经在目录下下载了用于升级的confluence软件。我需要为每个目录创建一个index.html 来列出目录。我尝试将以下内容添加到.htaccess目录中的文件中(我在某个地方看到了它,index.html目录中存在文件),但它不起作用:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

有没有实用程序或工具可以让我做到这一点?有人让我手动创建它,但我真的不想手动创建它。

更新

@Ipor Sircer / @Marcus Müller

我更新了httpd.conf文件 - 现在如下所示:

# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options +Indexes +FollowSymLinks
    IndexOptions +FancyIndexing +HTMLTable

    #Options None

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

这是在/var/www/html

pwd
/var/www/html

drwxr-xr-x 5 root root  86 Nov  7 18:10 .
drwxr-xr-x 4 root root  33 Aug 12 15:33 ..
drwxr-xr-x 4 root root  46 Nov  6 13:35 clients
drwxr-xr-x 3 root root  55 Nov  6 19:52 packages.confluent.io
drwxr-xr-x 3 root root  17 Nov  6 15:57 rpm

但是当我访问服务器时,我得到以下信息:

http://服务器

而如果我去server/rpm,我会得到这个:

http://服务器/rpm

我还需要更改什么才能/var/www/html从浏览器中看到下面的目录?

答案1

按照@Ipor Sircer建议,您可以FancyIndexing像在更新的配置中一样使用:

<Directory "/var/www/html">
    Options +Indexes +FollowSymLinks
    IndexOptions +FancyIndexing +HTMLTable
</Directory>

您可以阅读有关此选项的更多信息这里。但是,如果您没有启用 Apache 模块,这可能不起作用。

要在 Apache 配置中启用该mod_autoindex模块,请运行命令,sudo a2enmod autoindex然后使用 重新启动 Apache sudo systemctl restart apache2。那么你当前的配置应该根据需要显示目录内容。


更新: 我的错误a2enmod德比主义。您可以通过以下方式mod_autoindex在 RHEL 上启用:

  1. sudo nano /etc/httpd/conf/httpd.conf
  2. 在配置文件中,查找LoadModule包含加载各种 Apache 模块的指令的部分。添加以下行以启用mod_autoindex
LoadModule autoindex_module modules/mod_autoindex.so
  1. 保存并退出CTRL+x并确认y
  2. 重新启动阿帕奇sudo systemctl restart httpd

然后mod_autoindex 应该在您的系统上启用。


更新2:尝试按照以下说明进行操作这个帖子,这涉及删除welcome.conf文件并再次重新启动服务。

相关内容