简体   繁体   English

AWS ELB + nginx 反向代理 HTTP 504

[英]AWS ELBs + nginx reverse proxy HTTP 504

I have a node/express app in a Fargate container, which serves static files (html/css/js) in addition to hosting an API.我在 Fargate 容器中有一个 node/express 应用程序,除了托管 API 之外,它还提供 static 文件 (html/css/js)。 The network components in front of it look like so:它前面的网络组件如下所示:

(WAN) ---> (HTTPS HTTP/2) Proxy ELB ---> (HTTP HTTP/1) nginx reverse proxy ---> (HTTPS HTTP/1) App ELB ---> Fargate container

That might not be a standard stack, but it is HIPPA compliant, which is necessary for our application.这可能不是标准堆栈,但它符合 HIPPA,这对于我们的应用程序是必需的。

At some point in this chain, a connection is being dropped intermittently while responding to requests for the statically served files.在此链中的某个点,在响应对静态服务文件的请求时,连接会间歇性地断开。 It seems to happen to the same file repeatedly (say the main.js file, but has happened to a 377 byte icon) and happens about once every ten times I attempt to load the site.它似乎重复发生在同一个文件上(比如 main.js 文件,但发生在一个 377 字节的图标上),并且大约每十次我尝试加载该站点就会发生一次。 In Chrome DevTools, I can see that the request is pending for sixty seconds, after which I get an HTTP 504 back from one of the ELBs in the chain.在 Chrome DevTools 中,我可以看到该请求等待了 60 秒,之后我从链中的一个 ELB 获得了 HTTP 504。 I can change the timeouts of the ELBs and get a HTTP 502 instead because the ELB isn't timing out.我可以更改 ELB 的超时并获得 HTTP 502,因为 ELB 没有超时。

I've been all over the place trying to chase this down, including fiddling with the app itself (upgrade express, peek under the covers as much as possible to see when connections/sockets open and close) and I'm convinced that the application itself is not the problem (also, I'm hosting the app in 3 environments; this problem happens in 2 of them. Additionally, other node/express apps we've deployed with the same network stack work fine).我一直在试图追查这个问题,包括摆弄应用程序本身(升级快递,尽可能多地窥视以查看连接/套接字何时打开和关闭)并且我确信应用程序本身不是问题(另外,我在 3 个环境中托管应用程序;这个问题发生在其中 2 个环境中。此外,我们使用相同网络堆栈部署的其他节点/快速应用程序工作正常)。 I've come to be convinced the problem is with the AWS ELBs, nginx, or some complicated interaction between them.我开始确信问题出在 AWS ELB、nginx 或它们之间的一些复杂交互上。

nginx.conf (relevant portions): 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>;
        }

Any help is greatly appreciated!任何帮助是极大的赞赏!

Perhaps this answer I gave to a comparable question may help (or not -> I'm sorry) https://stackoverflow.com/a/66694872/15385504也许我对一个类似问题的回答可能会有所帮助(或没有 -> 对不起) https://stackoverflow.com/a/66694872/15385504

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM