Apache 无法确定 docker 容器上的服务器名称 [英] Apache couldn't determine servername on docker container
问题描述
我正在尝试为现有站点设置自定义 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
重要的是,当我登录容器的 shell 并手动运行 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>
推荐答案
如所示 此处 和在警告消息中,您可以将 ServerName
属性设置为 localhost
在 >/etc/apache2/apache2.conf
来自 Dockerfile.
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屋!