带有Wampserver的多个虚拟站点

时间:2012-09-12 15:38:28

标签: virtualhost wampserver

我在创建多个虚拟主机时遇到问题,我编辑C:\ wamp \ alias \ web.local看起来像这样:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website1.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website1.com"
    ServerName website1.local

    <Directory "C:/Documents and Settings/username/workspace/www.website1.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website2.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website2.com"
    ServerName website2.local

    <Directory "C:/Documents and Settings/username/workspace/www.website2.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website3.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website3.com"
    ServerName website3.local

    <Directory "C:/Documents and Settings/username/workspace/www.website3.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website4.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website4.com"
    ServerName website4.local

    <Directory "C:/Documents and Settings/username/workspace/www.website4.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

我的主机文件如下所示:

127.0.0.1       localhost
127.0.0.1       website1.local
127.0.0.1       website2.local
127.0.0.1       website3.local
127.0.0.1       website4.local

我已经重新启动了Wampserver,但我似乎无法访问website1.local,website2.local,website3.local或website4.local。我收到“网络错误(dns_unresolved_hostname)”错误消息。

请注意 localhost 是唯一可行的。

任何帮助表示感谢。

此致 斯蒂芬

修改

我在Windows XP上运行Wampserver 2.2。

1 个答案:

答案 0 :(得分:0)

一些问题,您不会通过编辑该文件来创建虚拟主机。

您使用此文件c:\ wamp \ bin \ apache \ apache.2.x.y \ conf \ extra \ httpd-vhosts.conf 然后你从https.conf文件中取消注释'Include conf / extra / chris-vhosts.conf',它靠近文件的底部。

现在你引用的VHOST定义看起来相当不错,所以你可能只是移动到正确的位置,你就可以了。

除外

使用包含空格的目录结构(例如

)是一个非常糟糕的主意
DocumentRoot "C:/Documents and Settings/username/workspace/www.website3.com"

将您的网站代码放置在类似

的结构中更安全
C:\websites\www\website3
C:\websites\www\website4

甚至

D:\websites\www\website4

哦,还有一件事,你只需要一个参考

NameVirtualHost *:80

通常是vhost定义文件的第一行。