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.
Adding as following
httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin webmaster@dummy-host2.example.com
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/
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 .
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.
The below link has a nice work around for this problem.
Pleas go through this, after you have set the virtual host.
but instead of the path you need to give the local domain name. for example "king.dev" link below
192.168.1.250(your system ip) king.dev
in the hosts.ics file in your system.
now you can access the website from your mobile typing in your browser like.
192.168.1.250:4000[if you have set the port]/your_file.html
your local website will be displayed in the mobile device
you can also have a look at
http://www.tech-otaku.com/local-server/accessing-localhost-virtual-hosts-network-computer/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.