gpt4 book ai didi

node.js - Node 服务器在本地主机上的端口 4200 上的 Web 浏览器中不可见

转载 作者:IT王子 更新时间:2023-10-29 00:43:23 25 4
gpt4 key购买 nike

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

我能够启动服务器,它基本上是一个网络服务器,我能够使用 wget 从命令行调用它。但是,当我使用 Chrome 浏览器将其拉出时,出现连接被拒绝的错误。

我想我更改了 Chrome 默认设置,使其不那么严格(比如不加载本地内容)。

我可以使用 ng serve 运行服务器,我已经尝试将主机指定为 0.0.0.0、127.0.0.1 和本地主机 - 但没有成功。

我怀疑这与 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

最佳答案

启动服务器:

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

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

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

关于node.js - Node 服务器在本地主机上的端口 4200 上的 Web 浏览器中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51218593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com