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


当前回答

本地服务器机:Linux

访问机器:iPad 13.5.1

我了解到本地服务器的主机IP需要设置为0.0.0.0,以便其他机器访问它。执行sudo netstat -anp检查本地服务器端口。我发现它运行在127.0.0.1或localhost上,所以其他机器无法访问它。我将应用程序配置更改为在主机IP 0.0.0.0上运行。然后,我使用<internetIP>:<端口>访问本地服务器,它工作正常

其他回答

For Mac users, open up the Network Utility (You can find this by typing cmd + space which will open spotlight and then in spotlight start typing Network Utility). Select Network Utility, when it's open, your IP address will be found next to the label IP Address. So basically with the IP, you can get into any open ports on your local mac e.g. if your website is running locally on localhost:3000 and your ip address is 154.31.92.0 then from your phone you can get the website simply by typing 154.31.92.0:3000 into a browser.

PS-这只适用于手机和电脑在同一个网络上

对我来说 首先我把我的电脑和手机连接在同一个网络上,你可以从电脑上ping你的手机来测试连接。

我用GGTS(Groovy/Grails Tool Suite)在本地运行我的项目,然后使用PC IP地址从移动设备访问网站,它的工作非常好。

PS.从本地运行,它会给出url (http://localhost:8080/projectname),如果你试图从手机访问你的本地网站,你应该用PC IP地址替换localhost

你可以试试ngrok.io。工作原理与localtunnel相同。 下载适合您的操作系统的应用程序。试着这样跑:

linux:

./ngrok http 8000

8000是应用程序正在运行的端口号。

windows:

 ngrok.exe http 8000

在mac上另一种快速而肮脏的方法是打开xcode(如果你安装了它),并在模拟器上运行safari。在这里输入localhost也可以。

您可以使用计算机的ip代替http://localhost。

但它可能无法访问。您必须编辑服务器软件的httpd.conf(或等效的配置文件)。我现在没有安装php,但你可以搜索关键字:“允许从或/目录”

注意:运行XAMPP的PC的IP必须是静态IP(不是DHCP分配的),否则每次重启PC时都需要手动检查。