Apache中基于名称的虚拟主机

我在configuration基于名称的虚拟主机时遇到了一些麻烦。

我可以用一个空白的httpd.conf文件启动“service apache2 start”服务器,并且它将运行在所有指向/ var / www的地方。


当我填写httpd.conf时:

# Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /www/kevins_playground ServerName home.coolkev.com # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /www/flatline_and_co ServerName www.flatline_and_co.com # Other directives here </VirtualHost> 

运行“service apache2 start”时出现此错误

 root@kevin-server:/etc/apache2# service apache2 start * Starting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [Thu Jul 26 20:10:01 2012] [warn] NameVirtualHost *:80 has no VirtualHosts (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs Action 'start' failed. The Apache error log may have more information. 

我find了解决办法,

  1. 我删除了所有对httpd.conf的更改,对我来说,这留下了一个空白的文件。
  2. 我复制了两个虚拟主机的./sites-available/中现有的默认站点文件。
  3. 我编辑了这两个文件,并在有意义的地方replace了值,我认为这应该是显而易见的,他们需要改变(网站基础文件夹,网站URL)。
  4. 我创build了像你应该在./sites-enabled/
  5. 我重新启动Web服务器的“sudo服务apache2重新启动”,它的工作。

我认为这个问题源于parsing这些文件时,Apache发现了两个文件,分别是<VirtualHost>,我的httpd.conf和./sites-available/中的默认网站configuration

只要你没有碰到默认的虚拟主机(它已经包含一个NameVirtualHost *:80指令),你就不应该复制默认的行为。

既然你必须忍受Debuntu,为什么不去用它,把你的虚拟主机放在/ etc / apache2 / sites-enabled /中,每个文件一个?