繁体   English   中英

docker apache 容器将 /usr/local/apache2/htdocs 作为 DocumentRoot 而不是 /var/www/html

[英]docker apache container serves /usr/local/apache2/htdocs as DocumentRoot instead of /var/www/html

我有一个 docker-compose 和 apache.dockerfile 用于创建本地服务器。 这是一个非常基本的设置。

我在httpd-vhosts.conf中设置了一个虚拟主机,并且我知道服务器名称和别名是有效的,因为如果我去dev.flying我会看到“它有效!” 页面(这是 htdocs 中的默认 index.html)。

但是,为什么文档根声明也不起作用?

码头工人-compose.yml

services:
  apache:
    build:
      context: .
      dockerfile: apache.dockerfile
    container_name: dev_apache
    depends_on:
      - php
      - mysql
    ports:
      - 80:80
    volumes:
      - ./wordpress:/var/www/html:delegated

apache.docker文件

FROM httpd:alpine

ADD ./apache/httpd-vhosts.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf

httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin email@email.com
    DocumentRoot /var/www/html
    ServerName dev.flying
    ServerAlias dev.flying
    ErrorLog logs/dev.flying-error_log
    CustomLog logs/dev.flying-access_log commo

    <Location /var/www/html>
            ProxyPass http://localhost:9000/
            ProxyPassReverse http://localhost:9000/
            Order allow,deny
            Allow from all
    </Location>
</VirtualHost>

我认为您需要在此处查看一些文档(可能需要进行一些更改以适应您的配置)

httpd docker 官方镜像文档建议先导出配置

$ docker run --rm httpd:2.4 cat /usr/local/apache2/conf/httpd.conf > ./apache/my-httpd.conf # Dumping to your apache folder

然后在编辑后复制容器的编辑部分。 在这种情况下,您需要告诉 apache 包括取消注释该行的 vhosts 配置

# Include conf/extra/httpd-vhosts.conf

之后,您的虚拟主机配置将覆盖对服务器发出的任何请求,即使与ServerName不匹配(您将不再看到 htdocs 默认值)

docker-compose.yml - 示例

services:
  apache:
    image: httpd:alpine # Using the image directly since everything is accessible through the volumes
    container_name: dev_apache
    ports:
      - 80:80
    volumes:
      - ./wordpress:/var/www/html:delegated
      - ./apache/my-httpd.conf:/usr/local/apache2/conf/httpd.conf
      - ./apache/httpd-vhosts.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf

编辑

您还需要一个Directory 指令来授予/var/www/html目录中的权限,因为my-httpd.conf中的默认指令是拒绝整个服务器文件系统。 像这样的东西:

<VirtualHost *:80>
    <...> Your stuff <...>
    <Directory /var/www/html>
        Require all granted
    </Directory>

</VirtualHost>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM