apache2:无法可靠地确定服务器的完全限定域名,使用 127.0.1.1 作为 ServerName

use*_*402 73 ubuntu ubuntu-9.10 apache-2.2

当我(重新)启动 Apache 时,我不断收到此警告。

* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [ OK ]

这是我的etc/hosts文件的内容:

#127.0.0.1  hpdtp-ubuntu910
#testproject.localhost  localhost.localdomain   localhost
#127.0.1.1  hpdtp-ubuntu910

127.0.0.1   localhost
127.0.0.1   testproject.localhost
127.0.1.1   hpdtp-ubuntu910



# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Run Code Online (Sandbox Code Playgroud)

这是我的/etc/apache2/sites-enabled/000-default文件的内容:

<VirtualHost *:80>
  ServerName testproject.localhost
  DocumentRoot "/home/morpheous/work/websites/testproject/web"
  DirectoryIndex index.php
  <Directory "/home/morpheous/work/websites/testproject/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf /lib/vendor/symfony/symfony-1.3.2/data/web/sf
  <Directory "/lib/vendor/symfony/symfony-1.3.2/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

当我转到 时http://testproject.localhost,我得到一个空白页。

谁能发现我做错了什么?

crb*_*crb 52

默认情况下,Ubuntu 不会在 Apache 配置中指定 ServerName,因为它不知道您的服务器的名称是什么。它尝试对您的 IP 地址进行反向查找,但不会返回任何内容,因此它只需使用 IP 地址作为ServerName

要修复它,请在任何虚拟主机之外添加 ServerName 指令- 例如 in /etc/apache2/httpd.conf,或者为您的主要 IP 地址设置反向 DNS 响应 - 在这种情况下, 127.0.1.1

忽略它也完全没问题。

  • 然后,您可以在 VirtualHost 块中添加 ServerName/ServerAlias,以使 VirtualHost 仅匹配您想要的主机名。阅读 http://httpd.apache.org/docs/2.2/mod/core.html#servername 了解详情。 (7认同)
  • 这是违反直觉的。如果我添加了任何虚拟主机的 ServerName *outside* - 如何从同一个 Apache 服务器为多个虚拟主机提供服务?(这毕竟是命名虚拟服务器的重点)-除非,您是说我可以在(例如)/etc/apache2/httpd.conf 中拥有 1 个以上的 ServerName 条目 (3认同)

小智 27

这是一个快速修复:

echo ServerName $HOSTNAME > /etc/apache2/conf.d/fqdn
Run Code Online (Sandbox Code Playgroud)


Rya*_*arn 16

围绕这一警告的另一种方法是把一个完全合格的域名上127.0.1.1线/etc/hosts。它甚至不必是一个可以真正解析到 dns 服务器上的任何内容的 fqdn。

127.0.1.1  hpdtp-ubuntu910.lan  hpdtp-ubuntu910
Run Code Online (Sandbox Code Playgroud)

会做到这一点,同时还保留任何不期望额外.lan. 顺序很重要;应首先指定具有更多级别的名称,如本例中.lan地址位于其他地址之前的示例。


小智 7

此解决方案适用于我的开发需求:

背景:

Debian Linux Sid:
VirtualHost 开发:我有 10 个服务器名称(站点内的 10 个虚拟主机条目可用)

我为每个人分配了一个唯一的本地主机 IP 地址/etc/hosts

127.0.0.1   joe   localhost.localdomain   localhost
127.0.1.1   joe
127.0.1.2   joomla
127.0.1.3   schmoo
127.0.1.4   forrest
127.0.1.5   store
127.0.1.6   publisher
127.0.1.7   studios
127.0.1.8   drupal
127.0.1.9   graphics
127.0.1.10  wordpress
...

The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Run Code Online (Sandbox Code Playgroud)

如果您要添加另一个虚拟主机(我有很多用于开发),请向另一个本地主机 IP 地址添加一个条目,并在重新启动 Apache 2.2 之前启用该站点:

127.0.0.11 *newhost*
Run Code Online (Sandbox Code Playgroud)

对于要启用为 VirtualHost 文件的每个条目:

/etc/apache2/sites-available/

joe joomla schoo forrest 商店出版商工作室 drupal 图形 wordpress

所有虚拟主机都通过 a2ensite/a2dissite主机名启用/禁用

抑制错误

重新启动 Web 服务器:apache2apache2:无法可靠地确定服务器的完全限定域名,使用 127.0.0.1 作为 ServerName ...等待 apache2:无法可靠地确定服务器的完全限定域名,使用 127.0.0.1 作为 ServerName''

在[Debian 中的空文件] 中编辑httpd.conf/etc/apache2/httpd.conf

ServerName 127.0.1.1
Run Code Online (Sandbox Code Playgroud)

然后为您添加注释禁用的所有名称解析查找。

如果您忘记了:唯一的 VirtualHost *:80 条目只需要在ports.conf文件中,

/etc/apache2/ports.conf

**NameVirtualHost *:80**
Listen 80

<IfModule mod_ssl.c>
   # If you add NameVirtualHost *:443 here, you will also have to change
   # the VirtualHost statement in /etc/apache2/sites-available/default-ssl
   # to <VirtualHost *:443>
   # Server Name Indication for SSL named virtual hosts is currently not
   # supported by MSIE on Windows XP.
   Listen 443
</IfModule>

<IfModule mod_gnutls.c>
   Listen 443
</IfModule>
Run Code Online (Sandbox Code Playgroud)

在您的 VirtualHost 条目中省略VirtualHost *:80

示例:虚拟主机 joe

<VirtualHost *:80>
    **ServerAlias joe**
    **...**
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)


Nic*_*ick 6

ServerNamehttpd.conf 中的设置对我不起作用。我通过设置ServerName 127.0.0.1来修复它/etc/apache2/conf.d/name

我正在运行 Ubuntu 12.10 Alpha3 并ServerName在两个地方都进行了定义。

来源:http : //linuxconfig.net/manual-howto/error-solution-could-not-reliably-determine-the-servers-fully-qualified-domain-name.html


Dav*_*vid 5

您缺少服务器配置级别的 ServerName 条目。您需要在任何主机之外都有一个 ServerName 条目,以便 Apache 将其用作其默认值。

将 ServerName 条目放在 VirtualHost 中不会解决问题。请参阅ServerName 指令


小智 1

我相信您需要添加ServerName默认虚拟主机。由于它不存在,因此它采用默认 IP 地址。这是一种警告。我猜你的网络服务器仍然可以正常工作。