简体   繁体   English

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

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

I've built a very simple hapi.js app with the following code. 我用以下代码构建了一个非常简单的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);
});

However I keep getting a "502 Bad Gateway" error upon deploy. 但是,部署时我不断收到“502 Bad Gateway”错误。 I'm using a standard zip & upload method to deploy. 我正在使用标准的zip和上传方法进行部署。 The zip file contains a service.js file with the code above and a package.json file as shown below. 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"
  }
}

I've tried deploying with the node.js engines section removed, and also set it to 0.10.29 and then realized that the version of node.js available in Beanstalk on the 1.0.4 AMI images was 0.10.26, so changed it here to that version. 我已经尝试删除node.js引擎部分进行部署,并将其设置为0.10.29,然后意识到1.0.4 AMI图像上Beanstalk中可用的node.js版本为0.10.26,所以更改了它这个版本。 I've tried it locally and all runs well. 我在当地尝试过,一切运行良好。

In the error log I've got the following two logs that show the code running... 在错误日志中,我有以下两个日志显示正在运行的代码...

-------------------------------------
/var/log/nodejs/nodejs.log
-------------------------------------
Server running at: http://ip-172-31-3-9:3000

and then the errors when I try to hit the server with a browser. 然后当我尝试使用浏览器访问服务器时出现错误。

-------------------------------------
/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"

It looks like your server is listening on port 3000, but from the nginx log file, it's setup to proxy to a node app listening on port 8081 (See the "upstream:" part). 看起来您的服务器正在侦听端口3000,但是从nginx日志文件中,它设置为代理监听端口8081上的节点应用程序(请参阅“上游:”部分)。

You might want to try using the PORT environment variable instead of hard coding it to either value though - I'm pretty sure EB exposes this to your app. 你可能想尝试使用PORT环境变量,而不是将其硬编码为任何值 - 我很确定EB将此暴露给你的应用程序。 That'll make sure updates to the runtime don't break your setup. 这将确保运行时的更新不会破坏您的设置。

Please code to listen at available environment port as blow: 请编码在可用的环境端口监听:

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.

相关问题 Nodejs 502 Bad Gateway在Elastic Beanstalk AWS上部署Express - Nodejs 502 Bad Gateway Deploying Express on Elastic Beanstalk AWS 将Node.js页面部署到AWS Elastic Beanstalk之后,出现“ hell.php”错误和“ 502 Bad Gateway”错误 - Getting “hell.php” error and “502 Bad Gateway” error after deploying Node.js page to AWS Elastic Beanstalk 如何将 Hapi.js API 部署到 AWS Lambda 和 API 网关? - how to deploy a Hapi.js API to AWS Lambda and API gateway? 将 Hapi.js 应用程序部署到 AWS EC2 - Deploying Hapi.js app to AWS EC2 502 Bad Gateway在Elastic Beanstalk上部署Express Generator模板 - 502 Bad Gateway Deploying Express Generator Template on Elastic Beanstalk 在heroku中部署hapi.js应用 - Deploying hapi.js app in heroku 尽管CORS配置正确,但CORS 502 Bad Gateway,AWS Elastic Beanstalk Node.js服务器 - CORS 502 Bad Gateway, AWS Elastic Beanstalk Node.js server, despite proper CORS configuration 部署后 AWS 弹性 beanstalk Express 服务 502 Bad Gateway - AWS elastic beanstalk Express service 502 Bad Gateway after deployment Node.js和Docker- Elastic Beanstalk 502错误网关 - Node.js and Docker- Elastic Beanstalk 502 Bad Gateway 弹性beantalk上的node.js:Firefox 502错误网关 - node.js on elastic beanstalk: firefox 502 bad gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM