簡體   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