关于Apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 fo

本文介绍了如何解决Apache启动时出现的错误信息,即'Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName'。通过编辑配置文件并正确引用,可以解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文转自:

http://irayd.com/blog/about-apache2-could-not-reliably-determine-the-servers-fully-qualified-domain-name-using-127-0-1-1-for-servername/

最近准备学习php,所以就配了个apache2,突然发现每次启动apache都会提示 Apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName这个错误,百度了一番,分享下解决方法:

sudo gedit /etc/apache2/httpd.conf


里面加一行ServerName localhost就OK了;
有可能你没有这个文件或者这个文件是空的,添加就行了.
然后我重启apache,发现还是提升这个错误,又百度了一番,发现是apache的默认配置文件apache2.conf中没有引用这个httpd.conf配置文件,解决办法是在include httpd.conf这个文件:

sudo gedit /etc/apache2/apache2.conf

找到

# Include module configuration:
Include /etc/apache2/mods-enabled/*.load
Include /etc/apache2/mods-enabled/*.conf
……
# Include ports listing
Include ports.conf
……
# Include generic snippets of statements
Include conf.d/
……
# Include the virtual host configurations:
Include sites-enabled/


这些语句随便哪里插入:

# Include all the user configurations:
Include httpd.conf

就可以了.
还有一点,更改默认的web文档根目录:对于Ubuntu而言,默认的是/var/www。怎么知道的呢?apache2.conf里并没有DocumentRoot项,httpd.conf又是空的,因此肯定在其他的文件中。经过搜索,发现在/etc/apache2/sites-enabled/000-default中,里面有这样的内容:

NameVirtualHost *
<VirtualHost *>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/

这个就是了.更改成你想要的就可以了,当然别忘了设置权限哦!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值