重启Apache 2的问题

我正在尝试重启Apache 2:

sudo service apache2 restart 

但得到以下错误:

 * Restarting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message 

我试图改变

 sudo gedit /etc/apache2/httpd.conf 

出现一个空白文件,我添加了这个:

 ServerName localhost 

但是这个错误并没有消失!

我该如何解决这个问题?

我发现了这个: 当无法确定域名时,如何重新启动/重新加载Apache?

好消息! Apache正在重启成功。 Apache只是不确定你想从哪里提供服务,所以它默认选择你的localhost(127.0.0.1)。 要防止出现此消息,请通过在/etc/apache2/apache2.conf文件中添加以下行来阐明您要从localhost(127.0.0.1)提供服务:

 ServerName localhost 

在虚拟主机部分之外的配置文件中指定ServerName localhost是执行此操作的方法。

其他答案建议您修改/etc/apache2/httpd.conf 。 当apache从apt升级时,此文件被覆盖。 对于您不希望被覆盖的Apache配置,您应该创建一个新文件。 以下是进行此配置更改的“Debian方式”:

 # create the configuration file in the "available" section echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/servername.conf # enable it by creating a symlink to it from the "enabled" section sudo a2enconf servername # restart the server sudo service apache2 restart 

您的本地主机IP地址应为127.0.0.1,而不是127.0.1.1。 请正确设置/etc/hosts文件。 然后编辑httpd.conf文件:

 sudo -H gedit /etc/apache2/httpd.conf 

出现空白文件时,请添加此行,然后保存:

 ServerName localhost 

这是另一个解决方案:

之前:

 [root@centos ~]# /etc/init.d/httpd restart Stopping httpd: [ OK ] Starting httpd: httpd: apr_sockaddr_info_get() failed for centos.wks.local httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ] 

/etc/hosts文件中添加了192.168.226.131 centos.wks.local

注意:192.168.226.131是我的Apache服务器IP地址。

后:

 [root@centos ~]# /etc/init.d/httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]