问题描述
我正在尝试重新启动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
但是那个错误并没有消失!
我该如何解决这个问题?
最佳解决方法
我发现这个:How do I restart/reload Apache when it can’t determine the domain name?
Good news! Apache is restarting successfully. Apache just isn’t sure where you want serve from, so it’s choosing your localhost (127.0.0.1) by default. To prevent this message from appearing, clarify that you want to serve from localhost (127.0.0.1) by adding the following line into your
/etc/apache2/apache2.conf
file:ServerName localhost
次佳解决方法
在虚拟主机部分之外的配置文件中指定ServerName localhost
是实现此目的的方法。
其他答案表明你应该修改/etc/apache2/httpd.conf
。当apache从apt升级时,该文件被覆盖。对于不想覆盖的Apache配置,应该创建一个新文件。以下是”Debian way”以更改此配置:
# 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