gpt4 book ai didi

php - Docker 中的 Apache 不会提供站点

转载 作者:可可西里 更新时间:2023-11-01 01:01:21 24 4
gpt4 key购买 nike

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

这是 dockerfile

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"]

apache.conf

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

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

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

最佳答案

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

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

RUN rm -rf /etc/apache2/sites-enabled/000-default.conf

关于php - Docker 中的 Apache 不会提供站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24827869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com