user4777196
user4777196

Reputation:

How to point two website in windows wamp server with same ip

I have two websites www.test1.com and www.test2.com.I hosted both sites in windows wampp server with same IP called xx.xxx.xx.xx .But while opening both sites www.test1.com is comming.Here www.test1.com files are in 'test1' folder and www.test2.com are in 'test2' folder. I Tried virtual host in wampp...but its not working...

This is my \wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf file

<VirtualHost *:80>
     DocumentRoot "c:/wamp/www/test1"
     ServerName test1
     ServerAlias test1.com
 </VirtualHost>

<VirtualHost *:80>
     DocumentRoot "c:/wamp/www/test2"
     ServerName localhost
     ServerAlias test2.com
     <Directory  "c:/wamp/www/test2">
        AllowOverride All
    Require local
    Require all granted
    Allow from all
     </Directory>
 </VirtualHost>

This is my C:\Windows\System32\drivers\etc\hosts file

127.0.0.1      localhost
127.0.0.1      test1.com
127.0.0.1      test2.com

Upvotes: 0

Views: 1571

Answers (2)

RiggsFolly
RiggsFolly

Reputation: 94642

Both your domain names are going to the site defined first in the httpd-vhost.conf file because that is the default behaviour when Apache cannot find a site requested in the host definitions. It normally means you have done something wrong in the defining of your VHOSTS.

Your host definitions are a little wrong, and you are mixing Apache 2.2 and 2.4 security syntax which often causes problems, try these

# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access
<VirtualHost *:80>
    DocumentRoot "C:/wamp/www"
    ServerName localhost
    <Directory  "C:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
     DocumentRoot "c:/wamp/www/test1"
     ServerName test1.com
     ServerAlias www.test1.com
     <Directory  "c:/wamp/www/test1">
        AllowOverride All
        Require local
        Require all granted
     </Directory>
 </VirtualHost>

<VirtualHost *:80>
     DocumentRoot "c:/wamp/www/test2"
     ServerName test2.com
     ServerAlias www.test2.com
     <Directory  "c:/wamp/www/test2">
        AllowOverride All
        Require local
        Require all granted
     </Directory>
 </VirtualHost>

Now so that you can see the sites locally on the WAMPServer PC the hosts file should look like this. Remember, these entries only effect the PC containing the HOSTS file, and have no effect on internet access or the ability of a remote user to use these domain name.

# IPV4 loopback
127.0.0.1      localhost
127.0.0.1      test1.com
127.0.0.1      test2.com
# IPV6 loopback
::1      localhost
::1      test1.com
::1      test2.com

Upvotes: 2

Chet
Chet

Reputation: 3729

The first line needs to be

NameVirtualHost *:80

Upvotes: -1

Related Questions