首页 > 解决方案 > Apache Docker 容器中使用了错误的 DocumentRoot

问题描述

即使我DocumentRoot在配置中指定了 a,我也需要指定包含在其中的子文件夹DocumentRoot以加载 URL。

docker exec -it apache httpd -S显示加载的虚拟主机的输出:

me@server:/var/www/html$ docker exec -it apache httpd -S
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
192.168.2.35:80        localhost (/usr/local/apache2/conf/enabled-sites/default.conf:10)
ServerRoot: "/usr/local/apache2"
Main DocumentRoot: "/usr/local/apache2/htdocs"
Main ErrorLog: "/proc/self/fd/2"
Mutex default: dir="/usr/local/apache2/logs/" mechanism=default
PidFile: "/usr/local/apache2/logs/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

我的 Docker 容器卷:

"Binds": [
    "/var/www/html:/usr/local/apache2/htdocs:rw",
    "/etc/apache2/conf:/usr/local/apache2/conf:ro",
    "/var/log/apache2:/usr/local/apache2/logs:rw"
],

default.conf

<Directory /usr/local/apache2/htdocs/default>
        Options -Indexes 
        AllowOverride All
        Require all granted
</Directory>

<VirtualHost 192.168.2.35:80>
        ServerName localhost

        ServerAdmin webmaster@localhost
        DocumentRoot /usr/local/apache2/htdocs/default

        LogLevel debug

        ErrorLog logs/error.default.ca.log
        CustomLog logs/access.default.ca.log combined
</VirtualHost>

标签: apachedocker

解决方案


为虚拟主机指定的 IP 与 Docker 使用的 IP 不匹配。

在虚拟主机中使用*:80可以修复它。


推荐阅读