首页 > 解决方案 > AWS Elastic Beanstalk 为负载平衡环境中的大多数请求返回 502(日志中为 499)

问题描述

AWS Elastic Beanstalk对部署我的express.js APIs. 我已经使用了Classic Load Balancer使用端口的传入请求80 & 443,并将它们重定向inbound80EC2 实例上以供 NGINX 处理。

但是,当尝试使用浏览器或其他控制台应用程序与 Axios、request-promise 等库进行点击时,API 没有响应并502 error在一分钟后点击。这很奇怪,因为 API 几乎会在 1 或 2 秒的时间内立即发送响应。

当我从 Postman 控制台点击 API 时,响应很好。NGINX、ELB 和客户端应该有一些问题。express.js 应用程序运行良好,没有任何错误。

我想调试并从 AWS 控制台获取日志,以查看 NGINX 日志中有大量499 errors导致此问题的日志。此外,一些请求甚至不会从负载均衡器发送到 NGINX。

我想要一个解决方案来解决这个问题。此外,proxy_ignore_client_abort这是我多次发现的一种建议方式。但是,我对如何以 .ebextensions 方式使用它一无所知。如果对此有答案,这将有助于解决问题。

标签: node.jsamazon-web-servicesnginxamazon-elastic-beanstalkamazon-elb

解决方案


The solution to fix this issue was to follow these steps:

  1. Use a single instance based EB stack or prefer an application load balancer instead of the classic load balancer as the CLB terminated the connections to the EB intermittently for unknown reasons.

  2. Add a custom issued SSL (could be Let's Encrypt) in case it's a single instance config via the .ebextensions to copy the SSL keys to EB. In case it's ALB based, you can use ACM from AWS to configure the cert automatically.

  3. Now, the SSL config is to be added as per the instructions from AWS EB stack documentation for Application Load Balancer / Single Instance.

  4. Now the application will run without any 499 errors due to the load balancer.


推荐阅读