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


当前回答

如果您正在使用MAMP,在您的iPhone Safari浏览器中输入您的IP地址(例如192.0.0.63),然后输入端口号8888(例如192.0.63:8888),您将能够在您的iPhone中看到您的本地站点。

如果使用WAMP服务器,同样在iPhone safari浏览器中输入IP地址(比如192.0.0.63),就是这样。但是不要忘记从WAMP服务器的httpd.conf文件中删除deny。如果你从127.0.0.1开始查找allow线,在它上面或下面,你会看到deny from all;只需要删除这一行并重新启动WAMP服务器就可以了。

其他回答

如果你宁愿输入主机名而不是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/

看看这个答案,它讨论了通过直接Objective-C调用内部路由HTTP到支持HTTP的层/嵌入式web服务器(让我们假设HTTP服务器代码在同一个应用程序中,希望在web小部件中显示HTML)。

这样做的优点是稍微更安全(可能更快),因为不应该暴露任何端口。

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

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

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

首先,你必须确认你也通过mac浏览器上的mac ip访问服务器api。 如果不是,请确保您的服务器允许这样做,而不仅仅是localhost(127.0.0.1),通过在0.0.0.0上运行您的服务器 去iphone上的safari,通过api你的服务器serve: ex http://0.0.0.0/st进行get请求。Safari自动重定向到服务器你的mac运行(在你的mac ip) 如果你想在你的iphone应用程序上发出请求,它应该用[你的mac/服务器ip]替换request 0.0.0.0

如果你使用mac (OSX):

在mac上:

打开终端 运行“ifconfig” 找到ip地址为“192.xx.x.x”的行

如果你用地址测试你的网站:"localhost:8888/mywebsite"(这取决于你的MAMP配置)

在手机上:

打开浏览器(如Safari) 输入URL 192.xx . x.x.x:8888/mywebsite

注意:必须连接在同一网络(wifi)