访问本地主机外部

时间:2018-04-04 14:44:30

标签: angular angular-cli

除了本地主持人外,我如何提供角度项目?

我尝试使用ng serve --host 0.0.0.0 --port 4200这符合,没有任何错误。

但是当我输入另一个像ng serve --host 192.168.255.1 --port 4200这样的ip时,我收到以下错误。我选择这个IP因为我想使用openVPN在私有IP中提供我的应用程序

**

  

错误
  提供的主机192.168.255.6无法绑定。请提供不同的主机地址或主机名

**

版本

 - npm 5.5.1
 - node 6.10.3
 - angular-cli global 1.7.1 and local 1.0.0

1 个答案:

答案 0 :(得分:3)

正在运行ng serve --host 0.0.0.0 --port 4200

指定--host 0.0.0.0表示"侦听每个可用的网络接口"。这将允许您访问localhost之外的角度项目。

从另一台计算机/设备访问它:

  1. 运行ng serve --host 0.0.0.0 --port 4200
  2. 查找运行ng serve的计算机的IPv4地址
    • E.g。在Windows上,在命令提示符下输入ipconfig | findstr /i "ipv4"
  3. 导航至http://[IP found in step 2]:4200