【发布时间】: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