Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How access Apache Virtual Host with a mobile device?

Tags:

apache

dns

After setting up Apache virtual hosts with hostnames "server1" and "server2", how would I access them with my iPhone (or any mobile device) since there's no way modify the /etc/hosts file in iOS or Android?

My understanding is that you have to reference the virtual hosts by name (assuming you only have 1 IP address on your physical server), but there's no way to map those virtual hostnames to the single IP address on my physical server.

I'm running my server on my laptop using MAMP and my Vonage router/Apple Airport don't support DNS. Do I need to setup a local DNS server? Is there any easy way to run that on my laptop? Thanks.

like image 445
JMan Avatar asked Nov 02 '11 17:11

JMan


3 Answers

Adding as following

httpd-vhosts.conf

<VirtualHost *:8080>
    ServerAdmin [email protected]
    DocumentRoot "/opt/lampp/htdocs/api/www"
    ErrorLog "logs/app_error"
    CustomLog "logs/app_log" common
</VirtualHost>

httpd.conf:

Listen 80
Listen 8080

Then in your mobile you can use:

http://<your laptop address>:8080/
like image 178
o0omycomputero0o Avatar answered Nov 02 '22 17:11

o0omycomputero0o


You can't if you don't have a local DNS. As a workaround, you could setup your first VirtualHost to listen on the 80 port and the second one on the 81 (or 8080 or whichever ports you want) and access the server by using http://your.server.ip.addr:port.

like image 35
Renaud Avatar answered Nov 02 '22 19:11

Renaud


You could use IP aliasing and configure IP-based virtual hosts. But then you have to access the sites via IP from your mobile device. But I guess using different ports as @Renaud suggests is easier.

If you want to do it, add an IP alias using ifconfig <interface> inet <ip> add on Mac OS X. Then add a Listen <ip> and <VirtualHost ip> directive to your Apache configuration.

like image 20
Mattias Wadman Avatar answered Nov 02 '22 17:11

Mattias Wadman