[英]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 的设置。
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你有两个选择
400
, the LB will mark the target healhty400
,LB会标记目标健康/
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.或者,如果您想在不更改应用程序的情况下继续使用,则以下内容将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.