【发布时间】:2015-06-28 12:16:19
【问题描述】:
我将 node js 应用程序部署到 AWS EBS。当我运行应用程序时,我收到错误“502 Bad Gateway”nginx/1.6.2。这是我在日志中发现的。
env.elasticbeanstalk.com/" 2015/04/21 10:52:01 [错误] 3807#0: *86 connect() 在连接到上游时失败(111:连接被拒绝),客户端:172.31.4.86,服务器:,请求:“GET / HTTP/ 1.1”,上游:“http://127.0.0.1:8081/”,主机:“clinicaltrials-env.elasticbeanstalk.com”
这是我的 package.json 文件
{
"name": "Clinical_Trial_Analytics",
"version": "1.3.2",
"private": true,
"scripts": {
"start": "node main.js"
},
"dependencies": {
"express": "3.0.6",
"stylus": "0.31.0",
"jade": "0.27.7",
"mongodb": "1.2.7",
"moment" : "1.7.2",
"emailjs": "0.3.3",
"json2html": "1.0.0"
},
"engines": {
"node": "0.12.0",
"npm": "1.1.65"
}
}
这是我的 main.js 文件
var express = require('express');
var http = require('http');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 8080);
app.set('views', __dirname + '/server/views');
app.set('view engine', 'jade');
app.locals.pretty = true;
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: 'super-duper-secret-secret' }));
app.use(express.methodOverride());
app.use(require('stylus').middleware({ src: __dirname + '/client' }));
app.use(express.static(__dirname + '/client'));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
require('./server/router')(app);
http.createServer(app).listen(app.get('port'), function(){
console.log("Clinical Trials server listening on port " + app.get('port'));
})
我无法找出问题所在。是节点版本还是其他问题?提前致谢。
【问题讨论】:
-
您的代码可能有问题
-
它在 8080 本地工作正常
-
您的 Node.js 日志中有什么内容?就您的应用而言,
process.env.PORT中的内容是什么? -
请查找更新后的代码.. 我将 app.js 相应地重命名为 main.js,因为在弹性 beanstalk 中,app.js 在 npm install 之前被调用
-
已解决。我只是给了process.env.port。没有使用任何端口号。
标签: node.js amazon-web-services express nginx amazon-elastic-beanstalk