簡體   English   中英

“502 Bad Gateway”將hapi.js部署到AWS Beanstalk?

[英]“502 Bad Gateway” deploying hapi.js to AWS Beanstalk?

我用以下代碼構建了一個非常簡單的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和上傳方法進行部署。 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"

看起來您的服務器正在偵聽端口3000,但是從nginx日志文件中,它設置為代理監聽端口8081上的節點應用程序(請參閱“上游:”部分)。

你可能想嘗試使用PORT環境變量,而不是將其硬編碼為任何值 - 我很確定EB將此暴露給你的應用程序。 這將確保運行時的更新不會破壞您的設置。

請編碼在可用的環境端口監聽:

var port = process.env.PORT || 3000;
app.listen(port,function(){
      console.log('node server started at ' + port);
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM