我正在做一个移动网站,想用我的iPhone浏览器测试一下。我的Windows 7电脑和iPhone都在同一个无线网络上。如何从iPhone访问localhost ?现在我得到一个404错误。
当前回答
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/
如果你用的是Mac -
通过USB连接你的iPhone和Mac。 进入Network Utility (cmd+空格,输入“Network Utility”) 进入“信息”选项卡 点击显示“Wi-Fi”的下拉菜单,如图所示选择“iPhone USB”。
你会发现一个类似“xxx.xxx.xx”的IP地址。或者类似的。打开iPhone的Safari浏览器,输入IP_address:port_number 例如:169.254.72.86:3000
[注意:如果IP地址字段为空,请确保您的iPhone通过USB连接,退出网络实用程序,重新打开并检查IP地址。]
警告:自macOS大苏尔以来,网络实用程序已弃用。
在mac上另一种快速而肮脏的方法是打开xcode(如果你安装了它),并在模拟器上运行safari。在这里输入localhost也可以。
如果你进入你的网络设置,并获得Wi-Fi IP地址,如xxx.xxx.x。xxx:9000(:9000或任何开放的端口),确保您的移动设备也在相同的Wi-Fi/信号IP地址上。我花了一天时间试着让它工作,直到我把手机的蜂窝网络切换到相同的Wi-Fi连接/IP地址,它才工作。我一更新就打开了。
找到你系统的IP地址和你运行网站的端口。
假设您的IP地址是121.300.00.250,端口是8080。
[端口号:在运行页面时看到您的web浏览器,例如:localhost:8080/…]那么端口号是8080]
现在在你的手机转到121.300.00.250:8080/..你会找到你的网站。
重要提示:您必须确保您的服务器(例如Apache Tomcat)处于启动状态
推荐文章
- 是否可以为iPhone应用程序(如YouTube和地图)注册一个基于http+域的URL方案?
- 改变UISegmentedControl的字体大小
- 获取用户当前位置/坐标
- 获得推送通知,而应用程序在前台iOS
- 如何取消选定的UITableView单元格?
- 为跨源请求设置cookie
- applicationwillenter前台vs. applicationDidBecomeActive, applicationWillResignActive vs. applicationDidEnterBackground
- iOS 7导航栏文本和箭头颜色
- 为iPad和iPhone设计输入按钮
- 如何在我的iPhone应用程序中使用NSError ?
- 在整个UIWindow中获取UIView的位置
- Xcode“构建和存档”菜单项被禁用
- 在为设备编译时,Apple Mach-O连接器错误
- 没有找到用于调试模式的此可执行文件的有效配置文件
- 如何从iPhone应用程序发送邮件