How access Apache Virtual Host with a mobile device?

拟墨画扇 提交于 2019-12-12 10:37:22

问题


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.


回答1:


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.




回答2:


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/



回答3:


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.




回答4:


The below link has a nice work around for this problem.

Pleas go through this, after you have set the virtual host.

1.http://rocketmodule.com/blog/easy-and-free-way-test-local-sites-ipads-iphones-and-other-mobile-devices/

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/



来源:https://stackoverflow.com/questions/7984786/how-access-apache-virtual-host-with-a-mobile-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!