docker apache容器服务/usr/local/apache2/htdocs作为documentroot而不是/var/www/html
我有一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您将需要做的一些文档(也许有一些更改以适合您的配置)
httpd docker官方图像文档建议首先导出配置
,然后在编辑后,因为您要复制用于容器的编辑零件。在这种情况下,您将需要告诉Apache包括VHOSTS配置
在您的虚拟主机配置之后,即使不匹配
servername
(您都看不到该服务器)(即使您看不到该服务器的任何请求)(您将看不到该请求) htdocs默认值不再)docker -compose.yml - 示例
编辑
您也需要一个目录指令在
/var/var/www/html
目录中授予许可,因为my-httpd.conf
是拒绝整个服务器文件系统。这样的事情: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
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
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
Edit
Also you will want a Directory directive to give permission in
/var/www/html
directory since the default directive inmy-httpd.conf
is to deny the entire server filesystem. Something like this: