1

I have a virtual hosts running on my mac via MAMP Pro. After looking at this: Access Apache VirtualHost from any computer on LAN? I've decided to check my httpd-vhosts.conf file to see if the correct settings were being used.

I have not touched a single Apache config files to get these virtual hosts up and running because MAMP Pro provides an interface that allows me to do so (ie: https://i.stack.imgur.com/8zkwS.png). I've checked my ../conf/Apache/extra/httpd-vhosts.conf to see if any changes were made but nothing. This is the content of the file:

    NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/Applications/MAMP/Library/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "/Applications/MAMP/Library/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

(condensed, this is the full content of the file: http://pastie.org/9158063)

Where can I find the relevant httpd-vhost.conf files? Will altering the one line of code as pointed out in the link I've provided above allow be to access the virtual host from another device?

Community
  • 1
  • 1
Zaki Aziz
  • 3,592
  • 11
  • 43
  • 61
  • Is the problem that you can't access the server using you virtualhosts names i.e: `dummy-host.example.com` and `dummy-host2.example.com`? I guess you will have to add a mapping in the `hosts` file for each computer on your lan that you would like to be able to access the server using the above hostnames. – Cyclonecode May 13 '14 at 12:38
  • I can access the virtual host from the machine it's on. Say I only have a laptop (`192.168.1.1`) and a phone (`192.168.1.2`) on my LAN. The MAMP installation is on my laptop and virtual hosts `www.dummy-host.example.com` can be accessed via the laptop. Note that going to `127.0.0.1` on my laptop is different than going to `www.dummy-host.example.com`, Also Note accessing `127.0.0.1` is the same as `192.168.1.1` (on my laptop). When I try to access `192.168.1.1` from my phone I am shown (my laptop's) `127.0.0.1` instead of `www.dummy-host.example.com` – Zaki Aziz May 13 '14 at 21:59
  • Yes and this is probably because you have mapped your virtual host to `www.dummy-host.example.com` and when you try to access the server using only its ip it won't work. You will need to add a mapping between 192.168.1.1 and your virtualhost. If you were using an `/etc/hosts` file you simply would add `192.168.1.1 www.dummy-host.example.com` on you client machine to be able to access the server using the virtualhost name instead of the ip address. – Cyclonecode May 13 '14 at 23:39
  • Here's a different thread talking about this problem: http://stackoverflow.com/questions/7984786/how-access-apache-virtual-host-with-a-mobile-device I guess the solution would be to use ip-based virtual hosts or use a lokal DNS server that has a mapping between you servers ip and the virtualhost name. – Cyclonecode May 13 '14 at 23:41
  • Here is a couple of other links that has different solutions for this problem: http://clickontyler.com/blog/2013/02/view-virtual-hosts-iphone-ipad/ http://viget.com/extend/device-testing-local-virtual-hosts – Cyclonecode May 13 '14 at 23:50
  • I've actually solved this issue by upgrading to a new MAMP version that supports xip.io. The links you've posted actually did give me insight to solving the issue (when I tried it on a virtual host on a windows machine). You should write and answer so I can award you the bounty points. – Zaki Aziz May 14 '14 at 03:16
  • I added some of the comments and links as an answer=) – Cyclonecode May 14 '14 at 09:55

1 Answers1

2

I guess this is because you have mapped your virtualhost to www.dummy-host.example.com and it won't work to access the server using only its IP-address. You will need to add a mapping between the servers IP-address and server alias. This could easily be done by adding a new line into your /etc/hosts file on you client machine i.e:

192.168.1.1 www.dummy-host.example.com

Since you're using a phone you won't be able to edit any hosts file and then you could use IP-based virtual hosts or perhaps a setup a local DNS server.

Here are a couple of links with different solutions for this problem

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93