node.js - 使用 wget 访问本地服务器时出现读取错误
问题描述
我有一个节点应用程序在端口 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
解决方案
在服务器上,检查端口 5000 是否正在侦听
netstat -anp --tcp | grep 5000 | grep LISTEN
它应该告诉你有东西在听127.0.0.1:5000
或0.0.0.0:5000
。前者是环回地址(只能在服务器内部访问),后者是服务器上具有 IP 的任何接口(因此,如果本地防火墙允许,它可以在服务器外部访问)。
如果 5000 上没有任何东西在监听,那么 docker 容器很可能没有暴露端口。
- 您可以放入
EXPOSE 5000
您的 Dockerfile。 - 您可以添加
--expose 5000
到您的docker run
命令 - 您可以添加
-p 5000:5000
到您的docker run
命令
如果您在本地计算机上运行它时可以访问端口 5000,则它可能正在工作,因为您添加了一个环境变量来自动公开该端口。
推荐阅读
- android - 如何对齐 MaterialButton 上左侧的文本和图标(文本后直接带有图标)?
- html - Angular:在同一个按钮上使用(单击)和 routerLink
- rust - Rust 工作区 - 默认排除所有包
- python - 没有 Celery 的烧瓶后台任务
- formsflow.ai - 选择表单以关联工作流时出现“未经授权”
- nginx - nginx https 反向代理返回无限循环
- javascript - jQuery,bPopup:如何在右下角定位弹出窗口?
- cloudflare - 如何在本地主机上允许 CloudFlare 流式传输视频
- sql - 根据字段名称列选择
- python - 如何使用套接字将 Web 数据从 Python 流式传输到纯数据 (Pd)