需要在Apache上configuration虚拟主机的帮助

我的网站启用了以下内容:

# # Example.com (/etc/apache2/sites-available/adityaherlambang.com) # <VirtualHost *:80> ServerAdmin [email protected] ServerName www.adityaherlambang.com ServerAlias adityaherlambang.com # Indexes + Directory Root. DirectoryIndex index.html DocumentRoot /var/www/adityaherlambang.com/htdocs/ # CGI Directory ScriptAlias /cgi-bin/ /var/www/adityaherlambang.com/cgi-bin/ <Location /cgi-bin> Options +ExecCGI </Location> # Logfiles ErrorLog /var/www/adityaherlambang.com/logs/error.log CustomLog /var/www/adityaherlambang.com/logs/access.log combined </VirtualHost> 

在我的virtual.conf中有:

 # We're running multiple virtual hosts. # NameVirtualHost *:80 

我只是在这里教程。 为什么现在当我重新启动我的服务器时,我得到:

  * Restarting web server apache2 [Sun Aug 14 04:35:30 2011] [warn] NameVirtualHost *:80 has no VirtualHosts [Sun Aug 14 04:35:30 2011] [warn] NameVirtualHost *:80 has no VirtualHosts ... waiting .......[Sun Aug 14 04:35:42 2011] [warn] NameVirtualHost *:80 has no VirtualHosts [Sun Aug 14 04:35:42 2011] [warn] NameVirtualHost *:80 has no VirtualHosts 

我的etc主机看起来像:

 #127.0.0.1 localhost 127.0.0.1.:80 adityaherlambang.com # 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 

VirtualHost没有默认端口; 当你说<virtualHost *>你指的是所有地址上的所有端口。 您需要使用*:80来代替。

伊格纳西奥是正确的,但我只是想扩大。

如果你看看NameVirtualHost的文档。 你可以看到一个IP和一个端口的语法调用。 这并不意味着Apache会监听你在这里指定的端口,或者即使你只是使用NameVirtualHost *并不意味着它会监听每个端口。 Apache具有Listen指令 ,该指令定义了Apache侦听的端口。

通过设置NameVirtualHost *:80你正在做的是在端口80上的所有请求中说,通过基于名称的虚拟主机运行它。 所以,如果你只是有NameVirtualHost *告诉Apache不要紧,请求来自哪里,通过基于名称的虚拟主机运行它。 如果指定了一个IP,那么只有该IP会受到virutalhost的影响。

所以简单的答案将永远是你的NameVirtualHost匹配你的虚拟主机。 但我觉得理解为什么很重要。 因为有一天,你可能有那个疯狂的服务器,它有Listen 80 8080 81 ,NameVirtualHost只设置在8080和81上? 可能会发生。