【问题标题】:Can not connect to MongoDB Atlas in CPanel无法在 CPanel 中连接到 MongoDB Atlas
【发布时间】:2022-08-02 18:15:56
【问题描述】:

在 CPanel 中运行应用程序时 enter image description here

我有这个错误:

MongoServerSelectionError:连接 ECONNREFUSED 13.xxx.xx.xxxx:27017

在CPanel仪表板中,我added这个IP地址到防火墙

在MongoDB Atlass网络接口,我addedCPanel服务器ip地址:

这是完整的日志:

MongoServerSelectionError: connect ECONNREFUSED 13.xxx.xx.xx:27017
    at Timeout._onTimeout (/home/c1439621c/nodevenv/my-app-server/14/lib/node_modules/mongodb/lib/sdam/topology.js:312:38)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  reason: TopologyDescription {
    type: \'ReplicaSetNoPrimary\',
    servers: Map(3) {
      \'ac-fgw9tmo-shard-00-00.inp06zb.mongodb.net:27017\' => [ServerDescription],
      \'ac-fgw9tmo-shard-00-01.inp06zb.mongodb.net:27017\' => [ServerDescription],
      \'ac-fgw9tmo-shard-00-02.inp06zb.mongodb.net:27017\' => [ServerDescription]
    },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: \'atlas-109adn-shard-0\',
    logicalSessionTimeoutMinutes: undefined
  }
}
  • 1)你已经有一个允许世界连接的防火墙规则,所以这不是防火墙问题,而是潜在的安全问题。 2)错误是ReplicaSetNoPrimary. 3)您的副本设置不正确,连接字符串格式不正确等。这些细节不在您的问题中。 4) 根据副本 URL,您正在连接到 Atlas,因此问题出在您的应用程序上。
  • @JohnHanley,它在本地和 Heroku 中完美运行,我认为问题出在 cpanel 主机上
  • 什么在本地和 Heroku 中完美运行?

标签: node.js mongodb cpanel parse-server mongodb-atlas


【解决方案1】:

如果您已经在 MongoDB Atlas 中将您的 cPanel 服务器的 IP 地址列入白名单,并且您仍然收到“CONNECTION REFUSED”,则很可能您的 cPanel 服务器的防火墙正在限制端口 27017 上的传出连接。

如有必要,请联系您的托管服务提供商并询问他们 27017 是否对传出连接开放。如果他们缺乏技术支持,我强烈建议切换到托管托管服务提供商,这将帮助您解决此类问题并帮助您进行所需的任何防火墙配置。

【讨论】:

    猜你喜欢
    • 2020-09-13
    • 2019-10-31
    • 2019-06-08
    • 2019-10-13
    • 2021-06-25
    • 1970-01-01
    • 2020-02-22
    • 2020-07-25
    • 2020-10-12
    相关资源
    最近更新 更多