2

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.

user2236230
  • 47
  • 1
  • 6

2 Answers2

4

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

Community
  • 1
  • 1
Sarah Kemp
  • 2,670
  • 3
  • 21
  • 29
  • I have, but do I need to add anything into the httpd-vhosts.conf file? Many thanks. – user2236230 Apr 03 '13 at 16:16
  • Your code looks fine, it just looks like it isn't being used. I see you said the code you included is from httpd.conf - I assumed this was a typo, but is this code actually in httpd.conf and not in httpd-vhosts.conf? – Sarah Kemp Apr 03 '13 at 16:32
  • The only examples I have to test with keep all virtual host information in the httpd-vhosts.conf file. I would try moving the code you included to this file - I don't know that it will fix your problem, but even if it doesn't it's a good idea. You could also try changing the 127.0.0.1 to *:80 - both worked for me but you've obviously got something going on. Make sure you restart Apache after all this too... I know you said you are but it's easy to forget. – Sarah Kemp Apr 03 '13 at 16:46
  • Ok thanks.. I will remove the code and place in the httpd-vhosts.conf file and see what happens.... – user2236230 Apr 03 '13 at 16:49
  • I have moved the code from httpd.conf into httpd-vhosts.conf and now get the following message: The website declined to show this webpage HTTP 403 Most likely causes: •This website requires you to log in. What you can try: Go back to the previous page. More information This error (HTTP 403 Forbidden) means that Internet Explorer was able to connect to the website, but it does not have permission to view the webpage. For more information about HTTP errors, see Help. – user2236230 Apr 04 '13 at 13:48
  • Just to add, that if I change the above code to rather than 127.0.0.1 then the site displayed is whichever one is *:80 rather than 127.0.0.1 or if thay all are, then it's the first directive.... – user2236230 Apr 04 '13 at 14:03
  • Also, for more information, there are 2 urls both mapped to the IP address of my server: client1.domain.com and client2.domain.com and on my server in the hosts file I have entries for 127.0.0.1 localhost, 127.0.0.1 client1.localhost and 127.0.0.1 client2.localhost... – user2236230 Apr 04 '13 at 14:17
  • all changed to *:80 and everything now works! Thank you for all your help...!! – user2236230 Apr 04 '13 at 16:57
3

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 webmaster@homemail.net
    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>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149