我正在做一个移动网站,想用我的iPhone浏览器测试一下。我的Windows 7电脑和iPhone都在同一个无线网络上。如何从iPhone访问localhost ?现在我得到一个404错误。
当前回答
我想完成与最初请求相同的事情,并在这里寻找答案,并关闭了所有防火墙和病毒防护,但都无济于事。
然后,我在微软文档中找到了以下关于IIS express的声明: “IIS express不向另一台计算机上的浏览器提供请求,使其在企业环境中更容易获得批准”。
底线-你将不得不安装IIS(不是交付的IIS express)来让你的项目在你的计算机之外被看到。
来源: http://msdn.microsoft.com/en-us/library/58wxa9w5.aspx
希望这对那些正在发疯地关闭电脑上所有安全功能的人有所帮助。
其他回答
如果你使用Mac,进入系统首选项>网络,使用你的IP地址而不是本地主机。您也可以使用端口号。在我的例子中,我有一个在端口1448上运行的服务器,我可以使用iPhone预览192.168.1.241:1448。
从iPhone访问localhost将简单地做一个环回/尝试连接到它自己(如果它支持?)
你需要做的是找到你的桌面机器的IP(例如,如果是Windows,进入命令提示符并输入ipconfig或进入网络和共享中心并查看连接状态。
一旦你有了你的ip,只需从你的浏览器访问,例如http://192.168.0.102。
如果您正在运行防火墙,您可能需要在防火墙的入站安全中打开端口80(或您的网站正在运行的任何端口)。
注意:如果你想调试应用程序,不要忘记应用程序的端口 你的iPhone浏览器:http://192.168.0.102:3000。在本例中,3000是ReactJS使用的默认端口。
步骤:
我假设您已经启动了web服务器(默认端口:8080上的apache tomcat)。
windows 10下:
打开你的防病毒软件,进入防火墙部分,并找到端口 ,并添加“本地TCP/IP端口:8080”允许访问 从命令提示符获取机器IP地址。(IPv4地址) 从iPhone启动chrome浏览器,转到ip地址:8080地址。
希望这能有所帮助。
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-这只适用于手机和电脑在同一个网络上
如果你宁愿输入主机名而不是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/
推荐文章
- 如何为TableView创建NSIndexPath
- 如何比较两个nsdate:哪个是最近的?
- 使UINavigationBar透明
- iOS应用程序“应用程序无法验证”只在一台设备上
- 适用于所有iOS (iPhone/iPad/Apple Watch)设备的大小
- iPhone:如何获取当前毫秒数?
- 如何在iOS数字键盘上显示“完成”按钮?
- 当文本字段被选中时,滚动UITableView
- 我的iphone应用程序如何检测自己的版本号?
- CSS提交按钮奇怪的渲染iPad/iPhone
- iOS 6应用程序-如何处理iPhone 5的屏幕尺寸?
- 总是通过弱引用的自我在ARC块?
- 如何在iOS上获得设备制作和模型?
- 如何禁用滚动在UITableView表时,内容适合在屏幕上
- iOS模拟器截图存储在哪里?