配置虚拟主机的问题

时间:2009-05-25 14:47:46

标签: configuration xampp virtualhost

一些细节

  • XAMPP 1.7.1
  • 在vista和xp上测试操作系统

大家好。我在配置虚拟主机时遇到一些问题。 目前我有两个网站。

这是我的vhost.conf文件:

<VirtualHost *:80>
    ServerAdmin me@site.nl
    DocumentRoot c:/xampp/htdocs/site1/trunk/
    ServerName site1.local
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin me@site.nl
    DocumentRoot c:/xampp/htdocs/site2/trunk/
    ServerName site2.local
</VirtualHost>

当然,在我的主人档案中,我有

127.0.0.1 site1.local
127.0.0.1 site2.local

我已经多次重启apache和浏览器了。

这是我的问题:

http://site1.local有效。但是当我去http://site2.local时,我降落在site1.local。

任何想法?

1 个答案:

答案 0 :(得分:2)

尝试

<VirtualHost "site1.local">
    ServerAdmin spam@a1230912##ad#.nl
    DocumentRoot c:/xampp/htdocs/site1/trunk/
    ServerName site1.local
</VirtualHost>

<VirtualHost "site2.local">
    ServerAdmin spam@a1230912##ad#.nl
    DocumentRoot c:/xampp/htdocs/site2/trunk/
    ServerName site2.local
</VirtualHost>

你总是得到site1,因为Apache默认为第一个。

修改

取消注释

#NameVirtualHost *

NameVirtualHost *

在你的httpd.conf

我说(/etc/httpd/conf/httpd.conf)

126 # Listen: Allows you to bind Apache to specific IP addresses and/or
127 # ports, in addition to the default. See also the <VirtualHost>
128 # directive.
129 #
130 # Change this to Listen on specific IP addresses as shown below to 
131 # prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
132 #
133 Listen 127.0.0.1:80
134 NameVirtualHost 127.0.0.1

我的vhost文件有

<VirtualHost "www.whatever.com">
        DocumentRoot /var/www/html/whatever/pub
        ErrorLog logs/error_log
        ServerName www.whatever.com
...