后端是nginx+nodejs,经常性的nginx 502,nginx error log:
recv() failed (104: Connection reset by peer) while reading response header from upstream
nodejs error log: [Error: connection closed] undefined 'Error: connection closed\n at null.<anonymous> (/data/sites/mysite/node_modules/mongodb/lib/mongodb/connection/server.js:592:24)
目测是mongodb连接失败,看了mongodb日志: [initandlisten] connection refused because too many open connections: 819
db的连接方式如下: var db = mongoose.connection; db.on('error’, function(err) { console.error('Error in MongoDb connection: ' + err); mongoose.disconnect(); }); db.on('connected’, function() { console.log(‘Connect to MongoDb success.’); }); db.on('disconnected’, function() { console.log(‘MongoDB disconnected!’); mongoose.connect(dbURI, {server: {auto_reconnect: true}}); }); mongoose.connect(dbURI, {server: {auto_reconnect: true}});
每次重启node之后过上一小段时间就宕机了。 这里不懂怎么配置了,求助~~~