Docker 中的 Apache 不会交付站点

Exp*_*cat 8 php apache webserver apache2 docker

在 Docker 容器中安装 apache Web 服务器后,我想显示一个示例页面以确保其正常工作。但是我总是得到 404 Not found。

这是泊坞窗文件

FROM ubuntu:14.04
MAINTAINER <mail@example.org>
RUN DEBIAN_FRONTEND=noninteractive

# Install required packages
RUN apt-get -y update
RUN apt-get install -y apache2 libapache2-mod-php5 php5-gd php5-json php5-mysql php5-curl php5-intl php5-imagick bzip2 wget

# Enable the php mod
RUN a2enmod php5

# Configuration for Apache
ADD ./apache.conf /etc/apache2/sites-available/
RUN ln -s /etc/apache2/sites-available/apache.conf /etc/apache2/sites-enabled/
RUN a2enmod rewrite

RUN mkdir /var/www/test && echo "<html><body><h1>Yo</h1></body></html>" >> /var/www/test/index.html

EXPOSE :80

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Run Code Online (Sandbox Code Playgroud)

阿帕奇配置文件

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www

    <Directory /var/www/test/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

容器已启动并正在运行。端口 80 转发到主机上的 8080。

当我浏览到 localhost:8080 时,我可以看到 apache2 默认页面。但是,当我访问 localhost:8080/test/index.html 时,我只得到 404 Not found 。

Mar*_*hes 5

这是因为您仍然拥有默认sites-enabled配置。

要删除此文件,您应该添加一行来删除它(可能与添加新虚拟主机配置的位置大致相同):

RUN rm -rf /etc/apache2/sites-enabled/000-default.conf
Run Code Online (Sandbox Code Playgroud)