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

本文介绍了如何解决Apache2启动时出现的Couldnotreliablydeterminetheserver’sfullyqualifieddomainname错误。通过修改httpd.conf文件添加ServerName并确保被apache2.conf正确引入,以及更改默认文档根目录的方法。

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

关于Apache2: Could not reliably determine the server’s 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这个错误,百度了一番,分享下解决方法:

 
  1. sudo gedit /etc/apache2/httpd.conf

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

 
  1. sudo gedit /etc/apache2/apache2.conf

找到

 
  1. # Include module configuration:
  2. Include /etc/apache2/mods-enabled/*.load
  3. Include /etc/apache2/mods-enabled/*.conf
  4. ……
  5. # Include ports listing
  6. Include ports.conf
  7. ……
  8. # Include generic snippets of statements
  9. Include conf.d/
  10. ……
  11. # Include the virtual host configurations:
  12. Include sites-enabled/

这些语句随便哪里插入:

 
  1. # Include all the user configurations:
  2. Include httpd.conf

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

 
  1. NameVirtualHost *
  2. <VirtualHost *>
  3. ServerAdmin webmaster@localhost
  4. DocumentRoot /var/www/

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

root@jiang:/etc/apache2# apache2ctl -M | grep mpm 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 mpm_prefork_module (shared) root@jiang:/etc/apache2# root@jiang:/etc/apache2# systemctl restart apache2 root@jiang:/etc/apache2# systemctl status apache2apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2025-03-14 10:52:41 CST; 1s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 75126 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 75130 (apache2) Tasks: 6 (limit: 9373) Memory: 13.3M CGroup: /system.slice/apache2.service ├─75130 /usr/sbin/apache2 -k start ├─75132 /usr/sbin/apache2 -k start ├─75133 /usr/sbin/apache2 -k start ├─75134 /usr/sbin/apache2 -k start ├─75135 /usr/sbin/apache2 -k start └─75136 /usr/sbin/apache2 -k start Mar 14 10:52:41 jiang systemd[1]: Starting The Apache HTTP Server... Mar 14 10:52:41 jiang apachectl[75129]: AH00558: apache2: Could not reliably determine the server's fully qualified domain nam> Mar 14 10:52:41 jiang systemd[1]: Started The Apache HTTP Server. root@jiang:/etc/apache2# ss -tulpn | grep ':8080' tcp LISTEN 0 511 *:8080 *:* users:(("apache2",pid=75136,fd=5),("apache2",pid=75135,fd=5),("apache2",pid=75134,fd=5),("apache2",pid=75133,fd=5),("apache2",pid=75132,fd=5),("apache2",pid=75130,fd=5)) root@jiang:/etc/apache2# ^C root@jiang:/etc/apache2# cat /proc/sys/net/ipv6/conf/all/disable_ipv6 0 root@jiang:/etc/apache2# apache2 -V | grep -i ipv6 [Fri Mar 14 10:53:26.989867 2025] [core:warn] [pid 81207] AH00111: Config variable ${APACHE_RUN_DIR} is not defined apache2: Syntax error on line 80 of /etc/apache2/apache2.conf: DefaultRuntimeDir must be a valid directory, absolute or relative to ServerRoot -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) root@jiang:/etc/apache2#
最新发布
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值