【问题标题】:Node Server not Visible in Web Browser on Port 4200 on localhost本地主机上端口 4200 上的 Web 浏览器中的节点服务器不可见
【发布时间】:2018-12-15 13:07:12
【问题描述】:

我在我的 Pixelbook 上以开发模式运行一个基本的 Angular 服务器。我觉得我在普通的 Ubuntu 开发箱上已经做过很多次了,但是这个 Chrome 风格的开发环境让我很烦恼。

我能够启动服务器,它基本上是一个 Web 服务器,并且我能够使用 wget 从命令行调用它。但是,当我使用 Chrome 浏览器打开它时,我收到了一个连接被拒绝的错误。

我认为我将 Chrome 默认设置更改为不那么严格(例如不加载本地内容)。

我能够使用ng serve 运行服务器,并且我已经尝试将主机指定为 0.0.0.0、127.0.0.1 和 localhost - 但没有运气。

我怀疑这与 Chrome 或 Pixelbook Linux 环境有关。

以下是我迄今为止所做的基本故障排除。还有其他想法吗?

→ ng serve --host=0.0.0.0 --port=4200
** Angular Live Development Server is listening on 0.0.0.0:4200, open your browser on http://localhost:4200/ **

Date: 2018-06-30T17:00:32.284Z
Hash: ebb64e6046efff317389AQ
Time: 8398ms
chunk {main} main.js, main.js.map (main) 10.7 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 227 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 5.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 15.6 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.06 MB [initial] [rendered]
ℹ 「wdm」: Compiled successfully.

::从命令行访问服务器 - OK::

→ wget 0.0.0.0:4200
--2018-06-30 17:04:29--  http://0.0.0.0:4200/
Connecting to 0.0.0.0:4200... connected.
HTTP request sent, awaiting response... 200 OK
Length: 581 [text/html]
Saving to: ‘index.html’

index.html                     100%[=================================================>]     581  --.-KB/s    in 0s      

2018-06-30 17:04:29 (37.5 MB/s) - ‘index.html’ saved [581/581]

::检查 index.html 以确认它是一个真正的 HTML 文件::

○ → head index.html 
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>MyAngularApp</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>

::打开 Chrome 并导航到 0.0.0.0:4200、localhost 等::

This site can't be reached
ERR_CONNECTION_REFUSED

::检查ip配置::

→ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:ea:0e:81:de brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
4: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:16:3e:21:1b:be brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 100.115.92.198/28 brd 100.115.92.207 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe21:1bbe/64 scope link 
       valid_lft forever preferred_lft forever

::检查 netstat 并查看正在监听哪些端口::

→ netstat -noa|grep "LISTEN "
tcp        0      0 0.0.0.0:4200            0.0.0.0:*               LISTEN      off (0.00/0/0)
tcp        0      0 0.0.0.0:5355            0.0.0.0:*               LISTEN      off (0.00/0/0)
tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN      off (0.00/0/0)
tcp6       0      0 :::5355                 :::*                    LISTEN      off (0.00/0/0)
tcp6       0      0 :::2222                 :::*                    LISTEN      off (0.00/0/0)
tcp6       0      0 :::8889                 :::*                    LISTEN      off (0.00/0/0)       

::验证 IP 表::

○ → sudo iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:4200

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DOCKER-USER  all  --  anywhere             anywhere            
DOCKER-ISOLATION-STAGE-1  all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (1 references)
target     prot opt source               destination         

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination         
DOCKER-ISOLATION-STAGE-2  all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere            
RETURN     all  --  anywhere             anywhere            

Chain DOCKER-USER (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere            

【问题讨论】:

  • 您是否尝试过清除 cookie 和缓存? Chrome 缓存疯狂,这可能会导致一些误报。如果这是我建议使用隐身模式的问题,这将在很大程度上防止缓存问题。
  • 好主意。我继续尝试。我仍然收到连接被拒绝错误。

标签: node.js linux angular development-environment


【解决方案1】:

启动服务器:

ng serve --host 0.0.0.0 --disable-host-check

查看:http://penguin.linux.test:4200/

penguin.linux.test 本质上是 Pixelbook 上的 localhost

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多