编辑 /etc/hosts 导致 Apache 服务器块丢失

编辑 /etc/hosts 导致 Apache 服务器块丢失

为了修复一些电子邮件 (SPF) 问题,我在/etc/hosts和中将我的 Ubuntu VPS 主机名更改为其 FQDN /etc/hostname。但是,现在,当我在浏览器中点击 URL 时,我会从 Apache 获得 404,而不是触发 中的阻止,从而/etc/apache2/sites-available/example.com重定向到www站点的版本。打字www.example.com仍然有效。

我的主机文件现在如下所示: 127.0.0.1 localhost 256.256.256.256 example.com # I am using a real IP and FQDN, obviously

我对此了解不多,不知道为什么 Apache 会出现 404 错误。它只显示错误The requested URL / cannot be found on this server,没有其他内容。为什么编辑我的hosts文件会导致这种情况?

答案1

该问题实际上出在默认的 Apache 配置文件(/etc/apache2/sites-available/000-default.conf)中。

取消注释该行:

#ServerName example.com并添加您服务器的 FQDN(完全限定域名)。

最后,运行sudo service apache2 reload让 Apache 获取配置文件的更改。

相关内容