node.js - AWS Elastic Beanstalk 为负载平衡环境中的大多数请求返回 502(日志中为 499)
问题描述
我AWS Elastic Beanstalk
对部署我的express.js APIs
. 我已经使用了Classic Load Balancer
使用端口的传入请求80 & 443
,并将它们重定向inbound
到80
EC2 实例上以供 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 方式使用它一无所知。如果对此有答案,这将有助于解决问题。
解决方案
The solution to fix this issue was to follow these steps:
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.
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.
Now, the SSL config is to be added as per the instructions from AWS EB stack documentation for Application Load Balancer / Single Instance.
Now the application will run without any 499 errors due to the load balancer.
推荐阅读
- spartacus-storefront - 斯巴达克斯 B2B 示例文件
- node.js - Puppeteer 无法获取 iframe
- java - 如何正确查询?
- javascript - 发布动态生成的多选下拉列表
- javascript - Electron 应用程序文件中的 JavaScript 被 HTML 表单中的脚本标记引用,无法将节点模块与 require 一起使用
- selenium - 包含非唯一嵌套元素的元素的 XPath
- google-apps-script - 根据电子表格数据将图表添加到 Doc
- reactjs - 拖动时反应成帧运动对象的大小增加
- amazon-web-services - 合并 AWS EBS 快照
- javascript - jQuery循环遍历多维数组并显示每个父数组的子数组