【问题标题】:apache 2 WEB_DOCUMENT_ROOT not correct, error logs shows "Cannot serve directory /var/www/html/"apache 2 WEB_DOCUMENT_ROOT 不正确,错误日志显示“无法提供目录 /var/www/html/”
【发布时间】:2021-12-19 15:19:07
【问题描述】:

这有点奇怪,这不是我第一次(当然也不是最后一次)在 docker cotainer 中使用 apache2。 我查看了配置 apache2.conf,对我来说它看起来不错:

<Directory />
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
</Directory>

我还将“000-default.conf”文件添加到可用站点: /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html/webroot

    <Directory /var/www/html/webroot>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>

</VirtualHost>

我也尝试将 webroot 文件夹路径添加到此 apache2.conf,但仍然无法正常工作:

<Directory /var/www/html/webroot>
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
</Directory>

我的项目文件(index.php 也是)位于 /var/www/html/webroot 路径,但浏览器显示 403 错误:“您无权访问此资源。”

我还检查了 apache 日志,我发现了这个......这很奇怪,因为我从未将这个文件夹“/var/www/html”设置为 DocumentRoot(不在 apache2.conf 或 000-default 中) .conf)。但是,如果我在 /var/www/html 中运行 info.php 脚本,我会得到 env DOCUMENT_ROOT = /var/www/html。

Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive

[![在此处输入图片描述][1]][1]

.httacess 文件:(位于/var/www/html)

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ webroot/    [L]
   RewriteRule    (.*) webroot/$1 [L]
</IfModule>

我检查了服务器是否正常工作,我可以在这里看到 phpinfo() http://loacalhost/info.php [1]:https://i.stack.imgur.com/QJJYC.png

【问题讨论】:

    标签: apache2 virtualhost


    【解决方案1】:

    我没有意识到 mod_rewrite.c 没有安装,这就是为什么忽略 .httacess fike :),现在一切正常。

    【讨论】:

      猜你喜欢
      • 2016-06-18
      • 2018-10-19
      • 2018-06-20
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 2013-12-31
      • 2011-05-17
      • 2021-06-04
      相关资源
      最近更新 更多