docker apache容器服务/usr/local/apache2/htdocs作为documentroot而不是/var/www/html

发布于 2025-02-12 04:01:27 字数 1305 浏览 0 评论 0原文

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

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

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

docker-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.dockerfile

FROM httpd:alpine

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

httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    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>

I have a docker-compose and apache.dockerfile which I am using to create a local server. It's a pretty basic setup.

I set up a virtual host in httpd-vhosts.conf and I know the server name and alias name is working because if i go to dev.flying I see the "It works!" page (which is the default index.html in htdocs).

However why wouldn't the document root declaration also be working?

docker-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.dockerfile

FROM httpd:alpine

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

httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时浪漫 2025-02-19 04:01:27

我认为您将需要做的一些文档(也许有一些更改以适合您的配置)

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

编辑

您也需要一个目录指令/var/var/www/html目录中授予许可,因为my-httpd.conf是拒绝整个服务器文件系统。这样的事情:

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

</VirtualHost>

Looking into some documentations here is what I think you will need to do (maybe with some changes to fit in your configuration)

The httpd docker official image docs recommends to export the configuration first

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

then after editing as you want copy the edited part for your container. In this case you will need to tell apache to include vhosts configuration uncommenting the line

# Include conf/extra/httpd-vhosts.conf

After that you virtual host configuration will override any request made for the server even if not matching the ServerName (you'll not see the htdocs default anymore)

docker-compose.yml - Example

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

Edit

Also you will want a Directory directive to give permission in /var/www/html directory since the default directive in my-httpd.conf is to deny the entire server filesystem. Something like this:

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

</VirtualHost>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文