make virtual host available through local network for iphone

会有一股神秘感。 提交于 2020-01-24 20:16:07

问题


I'm building a site on my localhost with a virtual host (mynewsite.com). Instead of uploading files to an actual server and I'd prefer to just test locally. I have the virtual host working on my desktop, I just want it to be available so I can see it on my iPhone or any computer on my network. So if I go to mynewsite.com on my iPhone it will display the site from my localhost. I think I need to do port forwarding but I'm having difficulty figuring it out. I'm on a Mac with MAMP.

How do I make the virtual host available to my iPhone through my Linksys router for testing?

My httpd.conf in MAMP looks like:

<VirtualHost *:80>
    DocumentRoot "/Users/jaysonp/Sites/mynewsite"
    ServerName "mynewsite.com"
    ServerAlias *.mynewsite.com
...

Then in my host file I have: 127.0.0.1 mynewsite.com

I should note that I can't just hit the ipaddress on my iPhone, there is code that checks against the domain name for the site to work.

Thanks!


回答1:


Please see my answer here. But basically, you just have to modify the Wifi settings in your iPad to use the IP address of your development machine as an HTTP proxy.




回答2:


You can use application to edit hosts file on the devices. Use iFile application. You can add more any hostname. You can see some picture here but I wrote in my language.

http://www.anop72.info/iphoneipad-เรียก-url-vhost-ทำอย่างไร/

Hope this helps.




回答3:


Just use the IP address of your virtual host. If your iPhone is on the same local network as your [virtual] host - the IP address will work fine.

I am not quite sure how you are defining "virtual" host - i.e. are you using Xen or VMware or something - or just running a web service on your dekstop?

If it is the former - you need to set up the IP services through Xen/VMware - if it's the later - its you desktop machine's IP address.




回答4:


You just need to change the host file of respective machine on which you want to see your virtual host.

For Example:

(in Linux and macOS ): /etc/hosts
(in Windows ): c:/windows/system32/drives/etc/hosts
(in Android ): Android is also the part of linux so the host file location is same in android too. But you need root access to change the host file.
(in iOS ): (anyone who knows can edit here!!)

Open the host file and

192.168.1.70    mynewsite.com

192.168.1.70 is the ip address of the machine in which your project is running on a virtual hosting -> mynewsite.com

All of the other devices must be connected to the same network .



来源:https://stackoverflow.com/questions/4114124/make-virtual-host-available-through-local-network-for-iphone

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