apache2,vhosts和servername指令

我正在我的Ubuntu桌面机上运行一个Apache开发环境。 当我启动apache,我得到错误

"apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName" 

我试图通过添加一行到我的apache.conf来解决这个问题:servername myhost

这消除了错误信息。 但是,使用这种configuration,对虚拟主机的请求不受尊重。 只有默认主机是可访问的。

有没有办法可以消除这个错误,并有虚幻?

撤消你在apache.conf的修改,把你的/etc/hosts文件改为:

 127.0.0.1 localhost 127.0.1.1 mycomputername # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts 

在第一行擦除重复的别名应该可以解决问题。 显然, /etc/hosts只能映射每行一个FQDN。

这是一个serverfault问题,我相信,但你做sudo a2ensite和激活conf文件,然后apache2ctl graceful

您可以执行apache2ctl -S来查看哪些虚拟主机已启用。 还要确保你已经更新了/etc/hosts以便你有一个指向127.0.0.1的条目。

对虚拟主机的请求不被尊重

/etc/apache2/conf.d/创build一个名为virtual.conf的文件。

该文件应该包含:

NameVirtualHost *

重新加载Apache( sudo /etc/init.d/apache2 reload )和虚拟主机应该工作。

你可以参考这个虚拟主机 。 希望能帮助到你。 🙂

尝试将ServerName vars添加到您的虚拟主机configuration。

例如,如果您将根ServerName var设置为“www.myhost.com”,则将您的ServerName设置为“virtualhostname.myhost.com”