node.js - 与 AWS EC2 上的基本 HTTP 服务器的连接被拒绝
问题描述
我知道有很多关于这个主题的资源,但我认为我做的一切都正确,但我仍然无法连接到我的服务器。
我在端口 80 上启动了一个简单的 node.js 服务器。
sudo netstat -tnlp | grep 80
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 3657/node
curl localhost:80
Welcome Node.js
我确保没有本地防火墙并且 VPC ACL 没有阻塞流量(不是我所期望的,因为这是一个全新的实例。)
service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
当我尝试从本地机器连接时的输出:
curl 3.xxx.xxx.xxx
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0
curl: (7) Failed to connect to 3.xxx.xxx.xxx port 80: Connection refused
关于接下来要检查的内容还有其他想法吗?
解决方案
我的问题的答案是https://stackoverflow.com/a/14045163/2369000。我复制的样板代码使用了一种仅侦听来自 localhost 的请求的方法。这可能是从 netstat 输出中检测到的,它表示127.0.0.1:80
监听地址。答案是使用.listen(80, "0.0.0.0")
或只是.listen(80)
因为默认行为是侦听来自任何 IP 地址的请求。
推荐阅读
- json-deserialization - com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从 START_ARRAY 令牌中反序列化“Todo”实例
- ros - 将 ROS 发布者缓冲区设置为 1 并将订阅者缓冲区设置为 1000 是否足够并且仍然不会丢失任何消息
- azure - Azure 管道运行时替换表达式
- .net-core - 有没有更好的方法在 Startup 类的 ConfigureServices 方法中注入所有依赖项
- ssl - Celery - [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败
- api-gateway - 使用 Kubernetes 的 Kong 数据库版本的文档很少
- python - 基于字典值映射将多索引数据帧与自身合并
- sql - 错误:记录类型尚未注册
- kendo-ui-angular2 - Kendo Angular 工具栏 - 单击溢出按钮无法正常工作
- ios - iOS 15:WKWebView 内的 Websocket 问题