Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have 2 websites running on my local machine that I'd like to view from other machines on the same network.

For /etc/apache2/sites-available/site1.com:

<VirtualHost *:80>
  ServerName site1.com
  DocumentRoot /var/www/answers/app/webroot
  DirectoryIndex index.php

  <Directory "/var/www/answers/app/webroot">
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all    
  </Directory>
</VirtualHost>

For /etc/apache2/sites-available/site2.com:

<VirtualHost *:80>
  ServerName site2.com
  DocumentRoot /var/www/answers2/app/webroot
  DirectoryIndex index.php

  <Directory "/var/www/answers2/app/webroot">
   Options FollowSymLinks
   AllowOverride All
   Order allow,deny
   Allow from all    
  </Directory>
</VirtualHost>

I have added 2 entries in the /etc/hosts file as:

127.0.0.1    site1.com
127.0.0.1    site2.com

Now, when I point the browser on my machine to site1.com, it shows me the first site and pointing the browser to site2.com, it shows me the second site.

However,when I type in the local IP of my machine in the browser, it always shows site2. How can I change it to switch between site1 and site2 ? Is there a way that I can view both the sites form another machine (esp. mobile devices over wireless network) ?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

On the other machine you would ordinarily add corresponding entries to the machines host file (as you have done on your machine) - pointing to the local IP address of your web server.

192.168.XXX.XXX  site1.com
192.168.XXX.XXX  site2.com

However, unless your mobile device (eg. phone?) is rooted, then you probably don't have access to the hosts file.

I think the ultimate/correct solution is to run a local DNS server: http://android.stackexchange.com/questions/9633/manually-set-a-hostname-for-ip-address-i-e-etc-hosts-equiv

However, you might be able to do this if your device supports an Ad Hoc network: http://android.stackexchange.com/questions/26692/connect-to-laptops-localhost-websites

share|improve this answer
1  
Thanks a lot ! I shall take a look at the links that you suggested. For now, I have modified the hosts file settings for site1 to *:80 and site2 to 127.0.0.1:80. That way, I can view site1 on my mobile device by typing the local IP. Since I just need to check site1 on the mobile device, it works for me for now. –  gentrobot Sep 9 '12 at 11:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.