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


当前回答

这个工具为我节省了很多,因为我在我的机器上没有管理权限,并且已经安装了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/

其他回答

如果你在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/

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

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

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

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

这样就行了。

要在两台笔记本电脑上进行测试,你可以使用http://localhost.run/或https://ngrok.com/这样的服务

如果在执行上面的步骤之后,仍然不能从其他设备访问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