node.js - AWS ELBs + nginx 反向代理 HTTP 504
问题描述
我在 Fargate 容器中有一个 node/express 应用程序,除了托管 API 之外,它还提供静态文件 (html/css/js)。它前面的网络组件如下所示:
(WAN) ---> (HTTPS HTTP/2) Proxy ELB ---> (HTTP HTTP/1) nginx reverse proxy ---> (HTTPS HTTP/1) App ELB ---> Fargate container
这可能不是标准堆栈,但它符合 HIPPA,这对于我们的应用程序是必需的。
在此链中的某个点,在响应对静态服务文件的请求时,连接会间歇性地断开。它似乎重复发生在同一个文件上(比如 main.js 文件,但发生在一个 377 字节的图标上),并且大约每十次我尝试加载该站点就会发生一次。在 Chrome DevTools 中,我可以看到请求等待了 60 秒,之后我从链中的一个 ELB 获得了 HTTP 504。我可以更改 ELB 的超时并获得 HTTP 502,因为 ELB 没有超时。
我一直在试图追查这个问题,包括摆弄应用程序本身(升级快递,尽可能多地窥视以查看连接/套接字何时打开和关闭)并且我确信应用程序本身不是问题(另外,我在 3 个环境中托管应用程序;这个问题发生在其中 2 个环境中。此外,我们使用相同网络堆栈部署的其他节点/快速应用程序工作正常)。我已经确信问题出在 AWS ELB、nginx 或它们之间的一些复杂交互上。
nginx.conf(相关部分):
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Authorization $http_authorization;
proxy_pass_header Authorization;
gzip on;
gzip_types text/plain application/xml application/javascript;
gzip_proxied no-cache no-store private expired auth;
gzip_min_length 1000;
if ( $http_x_forwarded_proto != 'https' ) {
return 301 https://<site URL>$request_uri;
}
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass https://<app ELB>;
}
任何帮助是极大的赞赏!
解决方案
也许我对类似问题的回答可能会有所帮助(或没有 -> 对不起) https://stackoverflow.com/a/66694872/15385504
推荐阅读
- javascript - conn.on('speaking') 不会触发不和谐机器人
- twos-complement - 用简单语言定义二进制补码
- c# - 建议的操作在 Microsoft Teams 中不可见
- emacs - 无法在 emacs 中执行 Plantuml
- c++ - 为什么 bool 和 _Bool 在内存中占用 1 个字节时只能存储 0 或 1?
- python - 使用 PySpark 将提取的整数从 url 添加到新列中
- google-cloud-platform - SDK Gcloud 日志记录时间戳过滤器
- android - Firebase Recyclerview 适配器和 Firebase UI 数据库
- tableau-api - 当表包含数据时,如何设置 Tableau 警报?
- ansible - 在角色/目录中安装所有角色的剧本