我目前正在做一个项目,我想在家里的两台笔记本电脑上进行测试,其中一台笔记本电脑连接到另一台本地主机。我正在使用XAMPP。我怎么做呢?


当前回答

假设两台机器都在同一个工作组中,在要连接的机器上打开cmd.exe,键入ipconfig,并在IPv4地址行中注明IP地址。

然后,在要连接的机器上使用

http://{the IP of the target machine}:{port number}

例如http://192.168.0.1:80,如果你的网站运行在端口80。

这样就行了。

其他回答

假设两台机器都在同一个工作组中,在要连接的机器上打开cmd.exe,键入ipconfig,并在IPv4地址行中注明IP地址。

然后,在要连接的机器上使用

http://{the IP of the target machine}:{port number}

例如http://192.168.0.1:80,如果你的网站运行在端口80。

这样就行了。

如果在执行上面的步骤之后,仍然不能从其他设备访问localhost,这是一个旁注。这可能是由于apache ports.conf配置为本地服务(127.0.0.1),而不是外部服务。

检查以下内容(适用于ubuntu apache2)

  $ cat /etc/apache2/ports.conf

如果设置如下:

NameVirtualHost *:80  
Listen 127.0.0.1:80  

然后将其更改回默认值

NameVirtualHost *:80  
Listen 80  

在Mac OS X上:

在终端中,运行ifconfig以获得计算机在其当前网络上的内部IP。它可能是192.168.1.140或10.0.1.174之类的东西。 启动服务器。例如,node server.js可以在某个端口上启动服务器。 在您的手机上,访问IP地址(例如192.168.1.140:3000),并确保指定端口。

如果你在Windows上,使用ipconfig获取本地IPv4地址,然后在Apache配置文件:httpd.conf下指定该地址,如下所示:

Listen: 10.20.30.40:80

重新启动Apache服务器并从网络上的其他计算机上测试它。

这个工具为我节省了很多,因为我在我的机器上没有管理权限,并且已经安装了nodejs。由于某种原因,我的网络上的配置不允许我访问其他机器,只是在浏览器上指向IP。

# Using a local.dev vhost
$ browser-sync start --proxy

# Using a local.dev vhost with PORT
$ browser-sync start --proxy local.dev:8001

# Using a localhost address
$ browser-sync start --proxy localhost:8001

# Using a localhost address in a sub-dir
$ browser-sync start --proxy localhost:8080/site1

http://www.browsersync.io/docs/command-line/