无法在 AWS Beanstalk 上运行 Nodejs 应用程序 [英] Unable to run Nodejs app on AWS Beanstalk

查看:31
本文介绍了无法在 AWS Beanstalk 上运行 Nodejs 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 AWS Beanstalk 上部署了 NodeJS 应用程序.我正在使用 AWS 代码管道从 Github 进行部署.部署后,当我访问 URL 时,它在网页上显示以下错误:

I have deployed NodeJS app on AWS Beanstalk. I am using AWS code pipeline for deployment from Github. After deployment when I am visiting URL, it's showing below error on web page:

502 错误网关nginx/1.18.0

502 Bad Gateway nginx/1.18.0

以下是我的基本节点代码:

Below is my basic node code:

const express = require('express');
const app = express();

const port = 3000 || process.env.PORT;

   app.get('/',(req,res) => {

   res.send("Hello there");
});

app.listen(port,(req,res) => {

 console.log(`App is running at ${port}`);
});

在下面的屏幕中,我的环境健康状况也很严重.我该如何解决?

In below screen health of my environment is also showing severe. How can I resolve this?

推荐答案

您的负载均衡器需要应用程序的一部分来ping"有时也称为心跳或健康检查".

Your load balancer needs a part of your application to "ping" which is sometimes called a heart beat or just a 'health check'.

这通常只是返回 HTTP 200 响应以让负载均衡器知道主机运行状况良好并且可以接收流量.

This is usually just something that returns a HTTP 200 response to let the load balancer know that the host is healthy and can receive traffic.

我不是 node.js 专家,但如果您可以创建一些端点,例如/health-check 并返回一个ok"或满足需要的 HTTP 200.

I'm not a node.js guy but if you can create some endpoints like /health-check and just return an "ok" or HTTP 200 that will satisfy the need.

你也可以让你的健康检查做一些事情,比如检查数据库连接是否也在运行.这取决于您的具体用例.

You can also have your health-check do something like check if the database connection is running as well. It's up to your specific use case.

然后在 beanstalk 中指定/health-check 作为负载均衡器要检查的 URL 端点.

Within beanstalk you would then designate /health-check as the URL endpoint for the load balancer to check.

也请查看此链接:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.healthstatus.html

这篇关于无法在 AWS Beanstalk 上运行 Nodejs 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆