2
votes

I have read through many posts and have configured WAMP for 2 sites on the same IP address as follows (httpd.conf extract):

#Tell Apache to identify which site by name
NameVirtualHost *:80

#Tell Apache to serve the default WAMP server page to "localhost"
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot "C:/wamp/www"
</VirtualHost>

#Tell Apache configuration for 1 site
<VirtualHost 127.0.0.1>
ServerName client1.localhost
DocumentRoot "C:/wamp/www_client1"
<Directory "C:/wamp/www_client1">
allow from all
order allow,deny
AllowOverride all
</Directory>
DirectoryIndex index.html index.php
</VirtualHost>

#Tell Apache configuration for 2 site
<VirtualHost 127.0.0.1>
ServerName client2.localhost
DocumentRoot "C:/wamp/www_client2"
<Directory "C:/wamp/www_client2">
allow from all
order allow,deny
AllowOverride all
</Directory>

I have also changed the Windows hosts file to add 127.0.0.1 client1.localhost etc. however when I restart the WAMP services, //client1.localhost and //client2.localhost go to the default site in the c:\wamp\www folder.

Any help really appreciated.

2
So you get a warning... Have you read it? What does it say?Álvaro González
The warning message is the standard "Virtualhost 127.0.0.1:80 overlaps with Virtualhost 127.0.0.1:80, the first takes precedence. Perhaps you need a virtualnamehost directive"user2236230

2 Answers

4
votes

Have you included your vhosts.conf in your httpd.conf?

Uncomment this line (the one that starts with 'Include') near the bottom of httpd.conf:

# Virtual hosts - leave this commented
Include conf/extra/httpd-vhosts.conf

Edit: It looks like the problem is that NameVirtualHost and VirtualHost have to match, so you can't have NameVirtualHost *:80 and VirtualHost 127.0.0.1. Instead, use NameVirtualHost *:80 and VirtualHost *:80 or NameVirtualHost 127.0.0.1:80 and VirtualHost 127.0.0.1.

If they don't match, you will see the behavior mentioned in your comment where either the virtual host that doesn't match the others will get hit, or if they are all the same, the first on (your default localhost) will get hit.

See this post for more: Wamp Server: Multiple Virtual Hosts are not working on Windows

3
votes

Try this configuration, its just a few minor mods to yours

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

## must be first so the the wamp menu page loads
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    <Directory  "C:/wamp/www">
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
</VirtualHost>

#Tell Apache configuration for 1 site
<VirtualHost *:80>
   ServerName client1.localhost
   DocumentRoot "C:/wamp/www_client1"
   <Directory "C:/wamp/www_client1">
      AllowOverride All
      order Allow,Deny
      Allow from all
   </Directory>
   DirectoryIndex index.html index.php
</VirtualHost>

#Tell Apache configuration for 2 site
<VirtualHost *:80>
    ServerName client2.localhost
    DocumentRoot "C:/wamp/www_client2"
    <Directory "C:/wamp/www_client2">
        AllowOverride All
        order Allow,Deny        
        Allow from all
</Directory>