【问题标题】:Read Error When Accessing Local Server with wget使用 wget 访问本地服务器时读取错误
【发布时间】:2021-09-10 01:17:10
【问题描述】:

我有一个节点应用程序在端口 5000 上运行(来自 docker 容器),但我无法访问它。

我在进入服务器后尝试运行wget http://localhost:5000,但出现以下错误:

--2021-09-09 18:44:44--  http://localhost:5000/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:5000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.

--2021-09-09 18:45:17--  (try: 2)  http://localhost:5000/
Connecting to localhost (localhost)|::1|:5000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.
Retrying.```

When I run the container on my local computer, I have no trouble accessing it this way, so I'm guessing it's something on the server, but I don't know where to look next.


EDITS

Output of `sudo netstat -anp --tcp | grep 5000 | grep LISTEN`


tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      16480/docker-proxy
tcp6       0      0 :::5000                 :::*                    LISTEN      16486/docker-proxy

【问题讨论】:

  • 可能有几个问题需要指出。向我们提供更多详细信息。它可能是您的port mapping [ --port 3000:3000 ] 才能正常工作。
  • 检查并正确暴露端口,添加了 netstat 输出的更新
  • 当您的服务器位于127.0.0.1localhost 时,有时会发生这种情况。将其更改为0.0.0.0。或至少,删除默认服务器位置。更重要的是,您还可以操纵IPv6在你的操作系统中禁用 IPv6。让我知道它是否正常工作。给我看你的服务器文件和Dockerfile | docker-compose.yaml 如果可能的话。

标签: node.js docker ubuntu


【解决方案1】:

在服务器上,检查端口 5000 是否正在侦听

netstat -anp --tcp | grep 5000 | grep LISTEN

它应该告诉你有东西在收听127.0.0.1:50000.0.0.0:5000。前者是环回地址(只能在服务器内部访问),后者是服务器上具有 IP 的任何接口(因此,如果本地防火墙允许,它可以在服务器外部访问)。

如果 5000 上没有任何东西在监听,那么很可能 docker 容器没有暴露端口。

  • 您可以将EXPOSE 5000 放入您的 Dockerfile 中。
  • 您可以将--expose 5000 添加到您的docker run 命令中
  • 您可以将-p 5000:5000 添加到您的docker run 命令中

如果您在本地计算机上运行它时可以访问端口 5000,则它可能正在工作,因为您添加了一个环境变量来自动公开该端口。

【讨论】:

  • tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 16480/docker-proxy tcp6 0 0 :::5000 :::* LISTEN 16486/docker-proxy 看起来像预期的那样暴露了.我正在使用 docker-compose 文件并且暴露了相应的端口
  • @SamAko,还有几件事要检查:- 1) 你确定节点应用程序在端口 5000 上侦听吗? 2) 是否配置了代理(确保未设置http_proxyhttps_proxy)。如果节点应用程序侦听端口 5000 并且该端口已暴露,那么您应该能够telnet localhost 5000 并获得连接。连接后,您可以发出 GET / HTTP/1.0 并获得某种 HTTP 响应。如果设置了代理,它将无法访问本地主机......但如果防火墙不阻止它,它可能可以访问服务器的 IP。你可以通过iptables -L查看防火墙规则
猜你喜欢
  • 2020-11-03
  • 2014-09-16
  • 2021-09-30
  • 1970-01-01
  • 2018-10-21
  • 2014-09-03
  • 1970-01-01
  • 1970-01-01
  • 2012-10-10
相关资源
最近更新 更多