【发布时间】:2014-10-04 23:42:42
【问题描述】:
我用以下代码构建了一个非常简单的 hapi.js 应用程序。
var Hapi = require('hapi');
var server = new Hapi.Server(3000);
server.route({
method: 'GET',
path: '/',
handler: function (request, reply) {
reply('Hello, world!');
}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});
但是,我在部署时不断收到“502 Bad Gateway”错误。我正在使用标准的压缩和上传方法进行部署。 zip 文件包含一个带有上述代码的 service.js 文件和一个如下所示的 package.json 文件。
{
"name": "hapi_aws_testing",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hapi": "^6.4.0"
},
"engines" : {
"node": "0.10.26"
}
}
我尝试在删除 node.js 引擎部分的情况下进行部署,并将其设置为 0.10.29,然后意识到 1.0.4 AMI 映像上 Beanstalk 中可用的 node.js 版本为 0.10.26,所以在这里把它改成了那个版本。我在本地试过了,一切运行良好。
在错误日志中,我有以下两个显示代码正在运行的日志...
-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
Server running at: http://ip-172-31-3-9:3000
然后是我尝试用浏览器访问服务器时的错误。
-------------------------------------
/var/log/nginx/error.log
-------------------------------------
2014/08/12 02:07:24 [error] 3457#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.13.177, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "consociation-test.elasticbeanstalk.com"
2014/08/12 02:07:26 [error] 3457#0: *4 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.13.177, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "consociation-test.elasticbeanstalk.com"
【问题讨论】:
标签: node.js amazon-elastic-beanstalk hapijs