Linux httpd:无法可靠地确定服务器的完全限定域名,使用 127.0.0.1 作为 ServerName
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9541460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
提问by user1220351
I tried to restart my Apache server on CentOS 5.0 and got this message:
我尝试在 CentOS 5.0 上重新启动我的 Apache 服务器并收到以下消息:
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd:无法可靠地确定服务器的完全限定域名,使用 127.0.0.1 作为 ServerName
Here is the /etc/hosts
file:
这是/etc/hosts
文件:
127.0.0.1 server4-245 server4-245.com localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
Here is the /etc/sysconfig/network
file:
这是/etc/sysconfig/network
文件:
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=server4-245
I also have this in the Apache httpd.conf file:
我在 Apache httpd.conf 文件中也有这个:
ServerName localhost
However, I still get the first error message when I restart Apache.
但是,当我重新启动 Apache 时,我仍然收到第一条错误消息。
采纳答案by Paul Stengel
Your hosts file does not include a valid FQDN, nor is localhost
an FQDN. An FQDN must include a hostname part, as well as a domain name part. For example, the following is a valid FQDN:
您的主机文件不包含有效的 FQDN,也不localhost
包含 FQDN。FQDN 必须包含主机名部分和域名部分。例如,以下是有效的 FQDN:
host.server4-245.com
Choose an FQDN and include it both in your /etc/hosts
file on both the IPv4 and IPv6 addresses you are using (in your case, localhost
or 127.0.0.1
), and change your ServerName
in your httpd configuration to match.
选择一个 FQDN 并将其包含在您/etc/hosts
正在使用的 IPv4 和 IPv6 地址(在您的情况下,localhost
或127.0.0.1
)的文件中,并更改您ServerName
的 httpd 配置以匹配。
/etc/hosts:
/etc/hosts:
127.0.0.1 localhost.localdomain localhost host.server4-245.com
::1 localhost.localdomain localhost host.server4-245.com
httpd.conf:
httpd.conf:
ServerName host.server4-245.com
回答by sparkyspider
In httpd.conf, search for "ServerName". It's usually commented out by default on Mac. Just uncomment it and fill it in. Make sure you also have the name/ip combo set in /etc/hosts.
在 httpd.conf 中,搜索“ServerName”。默认情况下,它通常在 Mac 上被注释掉。只需取消注释并填写它。确保您还在 /etc/hosts 中设置了 name/ip 组合。
回答by rizon
After the initial install of Apache server, I got the following error while restarting the Apache service on Ubuntu 12.04(Precise Pangolin)
初始安装 Apache 服务器后,在Ubuntu 12.04(Precise Pangolin)上重新启动 Apache 服务时出现以下错误
The solution is really simple. Just add the ServerName
directive to /etc/apache2/httpd.conf
:
解决方案非常简单。只需将ServerName
指令添加到/etc/apache2/httpd.conf
:
sudo nano /etc/apache2/httpd.conf
Add: ServerName localhost
添加: ServerName localhost
Finally restart the Apache server:
最后重启Apache服务器:
sudo /etc/init.d/apache2 restart
回答by riegersn
If you don't have httpd.conf
in folder /etc/apache2
, you should have apache2.conf - simply add:
如果你没有httpd.conf
in folder /etc/apache2
,你应该有 apache2.conf - 只需添加:
ServerName localhost
服务器名称本地主机
Then restart the apache2
service.
然后重启apache2
服务。
回答by user1992487
In the Apache httpd.conf
file:
在 Apachehttpd.conf
文件中:
ServerName: 127.0.0.1
回答by user2416772
So while this is answered and accepted it still came up as a top search result and the answers though laid out (after lots of research) left me scratching my head and digging a lot further. So here's a quick layout of how I resolved the issue.
因此,虽然这个问题得到了回答并被接受,但它仍然是最热门的搜索结果,而且答案虽然已经列出(经过大量研究)让我摸不着头脑并进一步挖掘。所以这是我如何解决问题的快速布局。
Assuming my server is myserver.myhome.com and my static IP address is 192.168.1.150:
假设我的服务器是 myserver.myhome.com 并且我的静态 IP 地址是 192.168.1.150:
Edit the hosts file
$ sudo nano -w /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 myserver.myhome.com myserver 192.168.1.150 myserver.myhome.com myserver ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ::1 myserver.myhome.com myserver
Edit httpd.conf
$ sudo nano -w /etc/apache2/httpd.conf ServerName myserver.myhome.com
Edit network
$ sudo nano -w /etc/sysconfig/network HOSTNAME=myserver.myhome.com
Verify
$ hostname (output) myserver.myhome.com $ hostname -f (output) myserver.myhome.com
Restart Apache
$ sudo /etc/init.d/apache2 restart
编辑主机文件
$ sudo nano -w /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 myserver.myhome.com myserver 192.168.1.150 myserver.myhome.com myserver ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ::1 myserver.myhome.com myserver
编辑 httpd.conf
$ sudo nano -w /etc/apache2/httpd.conf ServerName myserver.myhome.com
编辑网络
$ sudo nano -w /etc/sysconfig/network HOSTNAME=myserver.myhome.com
核实
$ hostname (output) myserver.myhome.com $ hostname -f (output) myserver.myhome.com
重启阿帕奇
$ sudo /etc/init.d/apache2 restart
It appeared the difference was including myserver.myhome.com
to both the 127.0.0.1 as well as the static IP address 192.168.1.150 in the hosts file. The same on Ubuntu Server and CentOS.
似乎差异包括myserver.myhome.com
主机文件中的 127.0.0.1 和静态 IP 地址 192.168.1.150。在 Ubuntu Server 和 CentOS 上也是如此。
回答by Jimit Shah
There are two ways to resolve this error:
有两种方法可以解决此错误:
Include /etc/apache2/httpd.conf
Add the above line in file /etc/apache2/apache2.conf
Add this line at the end of the file /etc/apache2/apache2.conf:
ServerName localhost
Include /etc/apache2/httpd.conf
在文件/etc/apache2/apache2.conf 中添加以上行
在文件/etc/apache2/apache2.conf的末尾添加这一行:
服务器名称本地主机
回答by John Creamer
I've resolved the fully qualified domain name message on different occasions by adding my server hostname to the /etc/apache2/httpd.conf file and to the /etc/apache2/apache2.conf
file.
我通过将我的服务器主机名添加到 /etc/apache2/httpd.conf 文件和该/etc/apache2/apache2.conf
文件,在不同场合解析了完全限定的域名消息。
Type hostname -f
in your terminal. This query will return your hostname.
输入hostname -f
您的终端。此查询将返回您的主机名。
Then edit the /etc/apache2/httpd.conf
file (or create it if it does not exist for some reason) and add ServerName <your_hostname>
.
然后编辑/etc/apache2/httpd.conf
文件(如果由于某种原因它不存在,则创建它)并添加ServerName <your_hostname>
.
Alternatively, I have also been able to eliminate the message by adding ServerName <your_hostname>
to the /etc/apache2/apache2.conf
file.
或者,我也可以通过添加ServerName <your_hostname>
到/etc/apache2/apache2.conf
文件中来消除该消息。
If all goes well, when you restart Apache, the message will be gone.
如果一切顺利,当您重新启动 Apache 时,该消息将消失。
回答by Skippy le Grand Gourou
Most answers suggest to just add ServerName localhost
to /etc/apache2/apache2.conf
.
大多数答案建议只添加ServerName localhost
到/etc/apache2/apache2.conf
.
But quoting Apache documentation?:
但是引用Apache 文档?:
The presence of this error message also indicates that Apache httpd was unable to obtain a fully-qualified hostname by doing a reverse lookup on your server's IP address. While the above instructions will get rid of the warning in any case, it is also a good idea to fix your name resolution so that this reverse mapping works.
此错误消息的存在还表明 Apache httpd 无法通过对您服务器的 IP 地址进行反向查找来获得完全限定的主机名。虽然上述说明在任何情况下都会消除警告,但修复您的名称解析也是一个好主意,以便此反向映射工作。
Therefore adding such a line to /etc/hosts
is probably a more robust solution?:
因此,添加这样的一行/etc/hosts
可能是一个更强大的解决方案?:
192.0.2.0 foobar.example.com foobar
where 192.0.2.0is the static IP address of the server named foobar
within the example.com
domain.
其中192.0.2.0是指定的服务器的静态IP地址foobar
的内部example.com
域。
One can check the FQDN e.g. with
可以检查 FQDN,例如
hostname -A
(shortcut for hostname --all-fqdn
).
(快捷方式hostname --all-fqdn
)。
回答by kenorb
Make sure you're editing the right httpd.conf
file, then the error about unreliable server's domain name should be gone (this is the most common mistake).
确保您正在编辑正确的httpd.conf
文件,然后关于不可靠服务器域名的错误应该消失(这是最常见的错误)。
To locate your httpd.conf
Apache configuration file, run:
要找到您的httpd.conf
Apache 配置文件,请运行:
apachectl -t -D DUMP_INCLUDES
Then edit the file and uncomment or change ServerName
line into:
然后编辑文件并取消注释或将ServerName
行更改为:
ServerName localhost
Then restart your apache by: sudo apachectl restart
然后通过以下方式重新启动您的apache: sudo apachectl restart