Apache2(XAMPP)虚拟主机指令不起作用(显然)

设置基于IP的虚拟主机时遇到一些问题。 首先,我在Windows 7上使用apachefriends(XAMPP 1.7.7和Apache 2.2.21)中的当前XAMPP。

“主”服务器(来自httpd.conf )的基本function非常完美。 但是现在我想要设置多个具有不同IP地址的虚拟主机,因为我的网卡configuration为使用从192.168.2.95到192.168.2.105的所有IP地址。

这是虚拟主机条目:

 <VirtualHost 192.168.2.96:80> DocumentRoot "/xampp/hegedocs/www" ServerName 192.168.2.96:80 </VirtualHost> 

httpd -D DUMP_VHOSTS说:

 PS G:\xampp\apache\bin> ./httpd -D DUMP_VHOSTS VirtualHost configuration: 192.168.2.96:80 192.168.2.96 (G:/xampp/apache/conf/extra/httpd-vhosts.conf:45) Syntax OK 

但我无法访问虚拟主机似乎没有听取192.168.2.96:80 apache – 没有显示此地址与netstat -a -b条目。

我发现这个问题:基于IP的虚拟主机不起作用。 只需在主机文件(foo.localhost,bar.localhost全部映射到相同的IP地址)中定义几个名称,然后使用基于名称的虚拟主机就可以毫无问题地工作。 当然,这不像IP地址那样便携,因为networking中的其他机器自然不知道这些名字……但是,只要它以某种方式工作…

这里有一些基本的东西,你可以尝试添加,以确保你得到正确的端口。

 # Ensure that Apache listens on port 80 Listen 80 # Listen for virtual host requests on all IP addresses NameVirtualHost *:80 

下面是appache的一个例子:

 <VirtualHost *:80> DocumentRoot /www/example1 ServerName www.example1.com # Other directives here </VirtualHost> <VirtualHost *:80> DocumentRoot /www/example2 ServerName www.example2.org # Other directives here </VirtualHost> 

我相信你以前看过这个,但是有时回头看看简单的东西是有帮助的。

我的设置工作正常运行2个网站在1框,使用ServerName http://www.example.com&#x3002;

希望这可以帮助!

确保apache知道vhost.conf文件的位置。 在httpd.conf的底部,你可能需要取消注释

 Include conf/*.conf