简体   繁体   English

AWS ELB 不健康 4xx

[英]AWS ELB unhealthy 4xx

I am using express.js and graphql for backend server which uses port 4000. I am trying to connect my server with ELB but the status returns unhealthy with error code 400 or 404. These are my settings about ELB.我正在为使用端口 4000 的后端服务器使用 express.js 和 graphql。我正在尝试将我的服务器与 ELB 连接,但状态返回不健康,错误代码为 400 或 404。这些是我关于 ELB 的设置。

  • Target group目标组

目标组

  • Target groups registered targets目标组注册目标

目标群体注册目标

  • Target groups health checks目标群体健康检查

目标群体健康检查

If I change the path to /graphql it returns 400, and just / returns 404. It is still working with no error when I call the API but it seems like I should fix it.如果我将路径更改为/graphql ,它返回 400,而/返回 404。当我调用 API 时,它仍然可以正常工作,但似乎我应该修复它。 Could anyone please tell me what can I do?谁能告诉我我能做什么?

The standard way to handle this case is to define the path in your express application for example /health or /ping which should return HTTP status code 200 .处理这种情况的标准方法是在 Express 应用程序中定义路径,例如/health/ping ,它们应该返回 HTTP 状态代码200

If /graphql does not return HTTP status code 200 the LB will mark the target unhealthy.如果/graphql没有返回 HTTP 状态代码200 ,LB 会将目标标记为不健康。

you have two option你有两个选择

  • Update Success codes to 400 , the LB will mark the target healhty更新成功码为400 ,LB会标记目标健康
  • Define path like / or /health and return status code 200 .定义//health类的路径并返回状态代码200

In express for example以快递为例

app.get('/health',function(req,res){
res.status(200).send("instance is healthy");
})

Then setting for LB will然后为 LB 设置将在此处输入图片说明

Or if you want to go without changing in the application the below will work.或者,如果您想在不更改应用程序的情况下继续使用,则以下内容将起作用。

在此处输入图片说明

Apollo supports a simple health check by default at this URL /.well-known/apollo/server-health ( source ), so you can add change the path in the target group from / to the URL Apollo 在这个 URL /.well-known/apollo/server-health ( source ) 默认支持简单的健康检查,所以你可以添加更改目标组中的路径从 / 到 URL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS API 网关偶尔会出现 4xx 错误 - AWS API Gateway occasionally gives 4xx Error AWS elastic beanstalk 100.0% 的请求出错 HTTP 4xx - AWS elastic beanstalk 100.0 % of the requests are erroring with HTTP 4xx AWS Auto Scaling Group 未从 ELB 检测到实例不健康 - AWS Auto Scaling Group does not detect instance is unhealthy from ELB AWS API 网关:如何在 cloudwatch 中记录 4XX 和 5XX 错误? 示例查找状态代码 413,请求实体太大错误是否记录在 Cloudwatch 中? - AWS API Gateway: How is 4XX and 5XX errors logged in cloudwatch? Example find Status Code 413, Request Entity too large error is logged in Cloudwatch? 使用 ELB 在 aws 实例上启用 https - Enable https on aws instance with ELB ELB 健康检查失败 AWS - ELB health check fail AWS AWS 中的 ELB 和 ALB 有什么区别? - What is the difference between ELB and ALB in AWS? SSL 到 AWS ELB 和 ELB 到 Tomcat 非 SSL / HTTP - SSL to AWS ELB and ELB to Tomcat non SSL / HTTP 如何自动获取DNS ELB ELB AWS Cloud formation - how to get DNS ELB automatically ELB AWS Cloud formation AWS:如何解决目标组中不健康的注册目标 - AWS : How to troubleshoot unhealthy registered target in target group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM