【发布时间】:2021-05-26 09:42:49
【问题描述】:
我在 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>;
}
非常感谢任何帮助!
【问题讨论】:
标签: node.js express nginx reverse-proxy aws-load-balancer