【问题标题】:MongoError: server sockets closed in Azure Web AppMongoError:Azure Web App 中的服务器套接字已关闭
【发布时间】:2016-01-22 14:46:34
【问题描述】:

所以我已经通过 git 将我的 express/mongodb 应用程序部署到我的 Azure Web 应用程序,当我打开应用程序的链接时,它一直在加载并显示一个黑页,我的路由不起作用,但静态文件只加载美好的。 所以我去看日志,我得到了这个。

D:\home\site\wwwroot\node_modules\mongodb\lib\server.js:236
        process.nextTick(function() { throw err; })
                                      ^
MongoError: server 127.0.0.1:3000 sockets closed
    at null.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\topologies\server.js:330:47)
    at g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at emit (events.js:172:7)
    at null.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:105:12)
    at g (events.js:260:16)
    at emitTwo (events.js:87:13)
    at emit (events.js:172:7)
    at Socket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\connection.js:145:12)
    at Socket.g (events.js:260:16)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at TCP._onclose (net.js:469:12)

npm ERR! Windows_NT 6.2.9200
npm ERR! argv "D:\\Program Files (x86)\\nodejs\\4.2.3\\node.exe" "D:\\Program Files (x86)\\npm\\3.5.1\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.2.3
npm ERR! npm  v3.5.1
npm ERR! code ELIFECYCLE
npm ERR! cinemat_iq@0.9.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cinemat_iq@0.9.0 start script 'node ./bin/www'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the cinemat_iq package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs cinemat_iq
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls cinemat_iq
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     D:\home\site\wwwroot\npm-debug.log

所以问题似乎出在 mongodb 的连接命令中,我目前将其作为

mongoose.connect('mongodb://127.0.0.1:3000/myapp');

我尝试更改为 localhost 而不是 127.0.0.1,并尝试了不同的端口,都导致相同的错误。

经过一些谷歌搜索/stackoverflowing 之后,我需要删除 mongodb 中的“锁定文件”,然后修复/重新启动 mongodb 服务。 问题是我无法使用 Azure 控制台(基于 Windows)找到此文件,并且无法运行任何 mongo 或 mongod 命令(它不被识别为内部或外部命令)。

那么我该怎么做才能让我的应用在 Azure 上运行?

【问题讨论】:

    标签: node.js mongodb azure


    【解决方案1】:

    据我所知,Azure WebApps 上没有直接提供任何数据库。所以问题是由于你的 webapp 的地址 localhost 或 127.0.0.1 上没有 mongodb 实例,而不是 MongoDB 连接字符串不正确。

    您可以尝试在Azure上创建一个MongoDB实例,并复制连接字符串更改代码mongoose.connect('&lt;the remote connection string&gt;')

    作为参考,您可以参考文档Announcing New MongoDB Instances on Microsoft Azure 了解MongoDB on Azure 以及如何开始。

    【讨论】:

      【解决方案2】:

      我认为 Azure App Service 环境中没有本地 mongoDB,尝试更改为连接到远程数据库(例如,将 mongoDB 托管在 Azure 虚拟机上)应该可以解决您的问题。

      【讨论】:

        【解决方案3】:

        你可以关注这个post到:

        1. 在 mongolab 上创建一个 mongoDB 实例(由 Azure 监督)
        2. 在 Azure Web 应用设置中设置 nodejs 环境变量
        3. 在你的 nodejs 代码中引用 env 变量来连接你的 mongoDB

        全部在QuickStart 部分

        【讨论】:

          猜你喜欢
          • 2013-01-16
          • 1970-01-01
          • 1970-01-01
          • 2015-01-21
          • 1970-01-01
          • 2014-09-24
          • 1970-01-01
          • 1970-01-01
          • 2014-12-08
          相关资源
          最近更新 更多