我正在做一个移动网站,想用我的iPhone浏览器测试一下。我的Windows 7电脑和iPhone都在同一个无线网络上。如何从iPhone访问localhost ?现在我得到一个404错误。


当前回答

老问题。对我有用的新答案我。

通过USB连接你的iPhone和电脑。

打开系统首选项>共享。

在左侧选项卡中选择Internet共享。这将显示您的互联网共享控件在右侧。

如果“Internet共享”后的复选框已启用,请取消勾选。

在“互联网共享”选项的右侧,勾选“iPhone USB”。

通过勾选其复选框启用Internet共享。可能会弹出一个窗口,要求您确认此操作。

找到顶部附近的消息,上面写着:“您本地网络上的计算机可以通过:xxxx.local访问您的计算机。记下xxxx说了什么——这是你的计算机的名称。你要把它输入到你的地址栏,所以我建议你把它编辑成一个简短的单词。

现在您应该能够从xxxx访问您的本地主机服务器。Local:yyyy,其中XXXX是上一步中您的名称,yyyy是服务器的端口号。

其他回答

如果你正在做一个php项目,你可以改变href的基本值:

<基地href = " < ?php echo str_replace("localhost","192.x.x.x",HTTPS_SERVER);?”> >

Localhost或127.0.0.1:取决于您的设置 192. x.x。X:您的本地IP地址 HTTPS_SERVER:之前的base href

这样做对于在手机上加载图像、css和js文件至关重要。

如果你使用的是mac,请确保编辑/etc/hosts文件。 根据上面的说明找到IP地址,并将以下行添加到该文件中

172.x.xx.x.x outer

在那之后,上面的步骤起作用了:在我的iphone浏览器中导航到正确的页面,访问http://172.x.xx.x.x:port http://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want

如果你进入你的网络设置,并获得Wi-Fi IP地址,如xxx.xxx.x。xxx:9000(:9000或任何开放的端口),确保您的移动设备也在相同的Wi-Fi/信号IP地址上。我花了一天时间试着让它工作,直到我把手机的蜂窝网络切换到相同的Wi-Fi连接/IP地址,它才工作。我一更新就打开了。

如果你宁愿输入主机名而不是IP地址

第一选择(快速方式):

您应该能够在您的iPhone上导航到http://my-macbook-pro.local/mywebsite。参见https://stackoverflow.com/a/9304094/470749

这种方法往往是有效的,因为'。域是一个特殊的保留字。

第二选择:

访问http://xip.io/,这是一个免费的服务,非常方便。无需配置。

然后,当您浏览到http://mysite.app.192.168.1.130.xip.io(使用服务器上的浏览器或LAN上的任何设备)时,它将显示托管在192.168.1.130上的页面。

如果您在该IP上存在的机器上运行Homestead,那么浏览http://mysite.app.192.168.1.130.xip.io:44300 (URL中包含端口)会以某种方式显示Homestead Vagrant虚拟机上的页面,地址为192.168.10.10。很神奇的。

第三种选择(它不依赖于服务,灵活但更复杂,只有当你有一个带有DD-WRT的路由器时才能工作):

如果您有一个本地服务器托管多个不同的站点,您希望通过不同的主机名(通过iPhone)访问这些站点,您可以这样做。

In your OS, change the name of your computer to something short, meaningful, and easy to remember, such as "RYANDESK". In your DD-WRT router settings: In Services > Services > Static Leases, set the MAC address of your server to point to a specific IP address, such as 192.168.1.108. Set its hostname to be the same as you named your computer earlier. "Client Lease Time" can be 1440 minutes. Be sure to press Save and also Apply Settings with every change. ("Save" doesn't seem to automatically apply the settings.) If you get an error, it's probably because the GUI design of DD-WRT is misleading, and you unnecessarily pressed "Add" for Static Leases. In DHCP Server > User Domain, choose "LAN & WAN". For "LAN Domain", set it to some short string, such as your initials without any punctuation (e.g. "xyz"). Probably avoid using the word "local" since there might be conflicts. Don't use real-world domains such as "com", "org", "net", etc. In Services > Services > DNSMasq, enable DNSMasq and "Local DNS" and configure "Additional DNSMasq Options" to be something like: address=/project1.xyz/project2.xyz/192.168.1.108 (where xyz is whatever you chose in the earlier step, the IP points to the specific machine, and project1 and project2 are whatever hostname you want to point to each of those projects (such as different Nginx configs). Ensure that your HOSTS file doesn't have any entries conflicting with what we've done. If you don't know what a HOSTS file is, you're probably fine. Flush your DNS cache and release and renew your local IP. Switch into and out of Airplane Mode on iPhone to flush DNS cache there too. Now you can browse to http://ryandesk.xyz in your iPhone (or in your desktop browser), and it will resolve to your local server. So hopefully you've set up your Nginx or Apache or whatever to be listening for that hostname. https://wiseindy.com/it/how-to-access-your-pcs-using-dns-names-with-dd-wrt/ http://www.howtogeek.com/69696/how-to-access-your-machines-using-dns-names-with-dd-wrt/

如果你不在同一个网络上,你可以使用这个叫做localtunnel的第三方工具

http://localtunnel.me/

它基本上是通过另一个服务器路由你的内容,然后你访问它。