Apache Docker容器中使用了错误的DocumentRoot

时间:2018-12-16 14:30:20

标签: apache docker

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

  • Works:192.168.2.35/default/index.html
  • 不起作用,但需要:192.168.2.35/index.html

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>

1 个答案:

答案 0 :(得分:0)

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

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