wamp中的多个虚拟主机

时间:2015-04-16 09:13:56

标签: php apache wamp virtualhost

我正在尝试在wamp中创建多个虚拟主机,但是当我添加第二个虚拟主机时,它会显示wamp主页。

这是我的主机文件:

#localhost name resolution is handled within DNS itself.
#127.0.0.1       localhost
#::1             localhost
127.0.0.1       localhost
127.0.0.1       www.site1.com
127.0.0.1       www.aksharen.com
::localhost
::www.site1.com
::www.aksharen.com

这是我的httpd-vhosts.conf文件:

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost        
</VirtualHost>

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/websites/www.site1.com/public"
    ServerName "www.site1.com"
    <Directory C:/websites/www.site1.com>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

<VirtualHost 127.0.0.1>
    DocumentRoot "C:/websites/www.aksharen.com/public"
    ServerName "www.aksharen.com"
    <Directory C:/websites/www.aksharen.com>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

我的第一个网站即www.site1.com工作正常。

2 个答案:

答案 0 :(得分:0)

你犯了一些错误

首先

127.0.0.1       localhost
127.0.0.1       www.site1.com
127.0.0.1       www.aksharen.com
::localhost
::www.site1.com
::www.aksharen.com

尝试将此更改为

127.0.0.1       localhost
127.0.0.1       www.site1.com
127.0.0.1       www.aksharen.com
::1  localhost
::1  site1.com
::1  aksharen.com

其次,我可以建议您对虚拟主机定义进行以下更改: -

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "c:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/websites/www.site1.com/public"
    ServerName site1.com
    ServerAlias www.site1.com
    <Directory "C:/websites/www.site1.com/public">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "C:/websites/www.aksharen.com/public"
    ServerName aksharen.com
    ServerAlias www.aksharen.com
    <Directory "C:/websites/www.aksharen.com/public">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require local
    </Directory>
    SetEnv APPLICATION_ENV "development"
</VirtualHost>

答案 1 :(得分:0)

为您的虚拟主机使用环回地址ips。即每个vhost应该有自己独特的回环ip。对于eaxmple,您的hosts文件应该类似于:

127.0.0.100      drupal.fox
127.0.0.2      play.fox
127.0.0.3     cake241.fox

所以你的vhosts文件应该是这样的:

<VirtualHost 127.0.0.100:80>
<Directory "c:/ampps/www/drupal.fox">
Options FollowSymLinks Indexes
AllowOverride All
Order deny,allow
allow from All
</Directory>
ServerName drupal.fox
ServerAlias drupal.fox
ScriptAlias /cgi-bin/ "c:/ampps/www/drupal.fox/cgi-bin/"
DocumentRoot "c:/ampps/www/drupal.fox"
ErrorLog "C:/ampps/apache/logs/drupal.fox.err"
CustomLog "C:/ampps/apache/logs/drupal.fox.log" combined
</VirtualHost>

当然,您必须创建一个新的虚拟主机条目,其IP等于hosts文件中的IP。