user3109875
user3109875

Reputation: 828

How to access different sites in wamp configured for multiple sites using ip

I'm developing locally using wamp and i've configured the enviroment to handle more than one site, but i want to access a specific site using an ip address, i don't know if i have to add a port after the 127.0.0.1.

The following are my host settings.

127.0.0.1       localhost
127.0.0.1       www.site1.net
127.0.0.1       www.site3.com

and on vhosts.

<VirtualHost *:80>
    ServerAdmin www.site1.net
    DocumentRoot "c:/wamp/site1/"
    ServerName www.site1.net
    ServerAlias www.site1.net
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin www.site2.com
    DocumentRoot "c:/wamp/site2/"
    ServerName www.site2.com
    ServerAlias www.site2.com
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

Problem

When i put 127.0.0.1 in my address bar it goes to site1, and i don't know how to access site2 using ip.

Why i want this. Because when i try to access this sites from another device on the same network they don't work unless i use this ip: 172.20.10.4, this on the iphone, and this ip goes to localhost which is site1 and then i can't access site2.

But just www.site.net or www.site2.com works on the machine running wamp.

Edit. This is what is tried.

I put some ports on the 'listen' part of the httpd.confi;

Listen *:80
Listen *:8182
Listen *:8383

And changed htttpd-vhosts;

<VirtualHost *:80>
        ServerAdmin localhost
        DocumentRoot "c:/wamp/"
        ServerName localhost
        ServerAlias localhost
        ErrorLog "logs/dummy-host.example.com-error.log"
        CustomLog "logs/dummy-host.example.com-access.log" common
    </VirtualHost>
<VirtualHost *:8181>
        ServerAdmin www.site1.net
        DocumentRoot "c:/wamp/site1/"
        ServerName www.site1.net
        ServerAlias www.site1.net
        ErrorLog "logs/dummy-host.example.com-error.log"
        CustomLog "logs/dummy-host.example.com-access.log" common
    </VirtualHost>
<VirtualHost *:8182>
        ServerAdmin www.site2.com
        DocumentRoot "c:/wamp/site2/"
        ServerName www.site2.com
        ServerAlias www.site2.com
        ErrorLog "logs/dummy-host.example.com-error.log"
        CustomLog "logs/dummy-host.example.com-access.log" common
    </VirtualHost>

This works on the devices, like on the iphone i can dial 172.20.10.4:8181 and it goes to site1 and 8182 goes to site two.

NEW PROBLEM

The url of the sites are now messed up, i can only access this sites by their ip with ports but not their domain names, so on the local machine 127.0.0.1:8181 goes to site 1 but www.site1.net doesn't find the server directory where this site is located.

Upvotes: 1

Views: 1357

Answers (2)

channelb
channelb

Reputation: 1

it will complicate, please do not use the same server's ip address not or the same server name.. each computer has unique ip, so provide the right ip and do not dupilcate the sitename of your project.. if you have 192.168.1.1 for site1.come then you should use 192.168.1.100 for site2.com.. 127.0.0.1 represents only 1 server ip and 1 sitename only.. please be guided with these difference because calling two persons in one address might result in one and your expecting to have 2 simultiniously.. thanks!

Upvotes: 0

RiggsFolly
RiggsFolly

Reputation: 94642

OK

If you use an ip address (from another PC on your network ) and not a url like www.site2.com Apache will not know what site it should run so it always picks the first site it find in the VHost definition file and takes the connection there.

So if you want to access your sites from other PC's on your internal network you either have to run your own DNS Server ( bit complicated ) or on each of the other PC's you need to setup their HOSTS file to know about your 2 sites i.e.

HOSTS FILE ON YOUR OTHER PC's assuming your WAMPSevrer is running on 192.168.1.10

192.168.1.10 www.site1.net 
192.168.1.10 www.site2.com 

Now these other PC's can use the correct url i.e. www.site1.net or www.site2.com and the Apache server will know which site to send the connection to.

Now I think you mentioned a Phone. This is a little more complex as you cannot get to the HOSTS file on a phone ( possibly you can if you have jailbroken it )

So for this I used a bit of a work around.

I use Fiddler, its a tool for viewing whats going up and down the line between a browser and the server from the PC running the browser. But you can also use it as a Proxy I think this is the documentation

Basically you set it up to listen for connections on lets say port 8888 and then you add a line to its existing script to tell it to go to a specific url when it sees connections on 8888, you can therefore use a url in the phone like 192.168.1.10:8888 to get to site1.net then change the script so it goes to site2.com

Its a bit conveluted but it worked for me.

Answer to second problem

You dont mention what version of WampServer or Apache you are using so I added a test for the version in the new lines.

You have made a few mistakes in the definition of your virtual hosts. See below for corrections

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    ServerAlias localhost
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
    <Directory  "D:/wamp/www">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
            Require ip 192.168.2      <- change to your subnet first 3 quartiles
        </IfDefine>

        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1 
            Allow from 192.168.2       <- ditto
        </IfDefine>
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "c:/wamp/www/site1"
    ServerName www.site1.net
    ServerAlias site1.net
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
    <Directory  "D:/wamp/www/site1">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
            Require ip 192.168.2  <- change to your subnet first 3 quartiles
    </IfDefine>

    <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1 
            Allow from 192.168.2       <- ditto
        </IfDefine>
    </Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "c:/wamp/www/site2"
    ServerName www.site2.com
    ServerAlias site2.com
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
    <Directory  "D:/wamp/www/site2">
        AllowOverride All

        <IfDefine APACHE24>
            Require local
            Require ip 192.168.2  <- change to your subnet first 3 quartiles
        </IfDefine>

        <IfDefine !APACHE24>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1 localhost ::1 
            Allow from 192.168.2       <- ditto
        </IfDefine>
    </Directory>
</VirtualHost>

Basically you need to tell each apache which IP's can access each vhosts folder. So you could keep your modified ports if you wish but keep the <Directory>...</Directory section.

Also check yor HOST file, it was probably a typo when you wrote your question but you have said your hosts file looks like this

127.0.0.1       localhost
127.0.0.1       www.site1.net
127.0.0.1       www.site3.com

It should be this:

127.0.0.1       localhost
127.0.0.1       www.site1.net
127.0.0.1       www.site2.com

Upvotes: 2

Related Questions