Apache无法确定Docker容器上的服务器名称 [英] Apache couldn't determine servername on docker container

查看:84
本文介绍了Apache无法确定Docker容器上的服务器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为现有站点设置自定义的docker容器.为此,我想为自己的自定义 vhost 配置提供一个 ServerName .

I am trying to set up a customized docker container for an existing site. To do so I want to provide my own custom vhost configuration with a ServerName.

但是当我尝试添加自定义的 vhost配置并重新启动apache时,我收到警告,提示Apache无法确定全局名称:无法可靠地确定服务器的标准域名,使用172.26.0.2.全局设置"ServerName"指令以禁止显示此消息

But when I try to add a custom vhost configuration and restart apache I get the warning that Apache was unable to determine the global name: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message

重要的是,当我登录到容器的外壳并手动运行 service apache2 restart 时,不再收到此警告.

What's important is the fact that when I log into container's shell and manually run service apache2 restart I do not get this warning anymore.

如何在构建中禁止显示?我是否应该以其他方式将 vhost 提供给作曲家?

How can I suppress that on the build? Should I provide the vhost to the composer somehow else?

这是我的 docker-compose.yml 类似:

version: '3'
services:
  web:
    build:
      context: ./etc/php
      args:
         - APP_HOST=${APP_HOST}
    ports:
      - ${APP_PORT}:80
      - ${APP_PORT_SSL}:443
    volumes:
      - ./var/bin/:/tmp/bin/
      - ./app/:/var/www/html/
      - ./log/:/var/log/
      - ./etc/php/conf/:/usr/local/etc/php/conf.d/
    environment:
      - VIRTUAL_HOST=${VIRTUAL_HOST}

然后, Dockerfile ,添加我自己的可用站点:

Then, Dockerfile that adds my own available site:

FROM php:7.0-apache
ENV TERM=xterm
LABEL maintainer="Derek P Sifford <dereksifford@gmail.com>" \
      version="0.15.2-php7.0"

ARG APP_HOST
ENV APP_HOST=$APP_HOST

ADD ./sites/app.conf /etc/apache2/sites-available/app.conf
RUN sed -i 's/ServerName APP_HOST/ServerName '$APP_HOST'/g' /etc/apache2/sites-available/app.conf

RUN sed -i 's/AllowOverride None/AllowOverride All/g' /etc/apache2/apache2.conf \
    && a2enmod rewrite expires \
    && a2dissite 000-default.conf \
    && a2ensite app.conf \
    && service apache2 restart

WORKDIR /app
EXPOSE 80 443

显然是站点配置:

<VirtualHost *:80>
    DocumentRoot "/var/www/html"
    ServerName APP_HOST

    SetEnv APPLICATION_ENV "development"

    <Directory "/var/www/html">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

推荐答案

如所示

As indicated here and in the warning message you can set the ServerName property to localhost in /etc/apache2/apache2.conf from within the Dockerfile.

这篇关于Apache无法确定Docker容器上的服务器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆