504网关超时-两个带负载均衡器的EC2实例 [英] 504 Gateway Timeout - Two EC2 instances with load balancer

查看:359
本文介绍了504网关超时-两个带负载均衡器的EC2实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是不可能的问题.我已经尝试了一切.我感觉好像有一个人在总机的某个地方,旋转着他的胡须.

This might be the impossible issue. I've tried everything. I feel like there's a guy at a switchboard somewhere, twirling his mustache.

问题:

我有运行应用程序的Amazon EC2.当只有一个实例且没有负载均衡器时,它可以正常工作.

I have Amazon EC2 running an application. It functions without issue when there is only one instance and no load balancer.

但是在生产环境中,我有两个相同的实例在一个负载均衡器后面运行,并且在执行某些任务时(例如生成PDF并将其附加到电子邮件的功能),以及使用Google Developer工具时都没有任何反应使用网络"标签,一旦达到超时(我将其设置为30秒),我会收到错误消息"504网关超时".

But in my production environment I have two identical instances running behind one load-balancer and when performing certain tasks, like a feature that generates a PDF and attaches it to an email, nothing happens at all, and when using Google Developer tools with the Network tab I get the error "504 Gateway Timeout" once the timeout hits (I have it set at 30 seconds).

我的数据库是外部的,在Amazon RDS上.

My Database is external, on Amazon RDS.

我认为....如果我可以强迫客户端保持与他们登录的初始服务器的连接,则此问题将得到解决,因为据我了解,当实例1尝试执行504网关超时时,接触到instance-2以执行任务.

I think.... If I could force a client to stay connected to their initial server they logged in at, this problem would be solved, because it's my understanding that the 504 Gateway Timeout is happening when instance-1 tries to reach out to instance-2 to perform the task.

这仅在使用负载平衡时发生,而在直接连接到我的两台服务器之一时则不会发生.

This happens ONLY WHEN using Load Balancing, but never when connecting straight to one of my two servers.

负载均衡器设置:

  • 负载平衡器在我的注册器上有一个CRECORD,因此app.myapplication.com指向myloadbalancerDNSname.elb.amazonaws.com
  • 负载均衡器有2个运行状况良好的实例,每个实例都在同一区域中,但它们位于不同的可用区域中.
  • 负载均衡器使用与实例相同的安全组(允许端口22、80和443上的所有IP)
  • 负载均衡器已启用跨区域负载均衡.
  • CORS(在Amazon S3中)启用了从*到*的GET,POST,PUT,DELETE(我不知道它如何与实例关联,但无论如何我都按照说明进行了操作)
  • 负载均衡器的监听器配置如下:
    • 负载均衡器协议:HTTP负载均衡器端口:80实例协议:HTTP实例端口:80
    • The load balancer has a CRECORD on my Registrar so that app.myapplication.com points to myloadbalancerDNSname.elb.amazonaws.com
    • The load balancer has 2 healthy instances, each in the same region but they are in different availability zones.
    • The load balancer is using the same Security Groups as the Instances (allow ALL IPs on ports 22, 80, and 443)
    • The load balancer has cross-zone load balancing turned on.
    • CORS (in Amazon S3) is enabled to GET, POST, PUT, DELETE from * to * (I have no idea how this is associated with my instances but anyway I did it as the instructions said)
    • The load balancer has listeners configured as such:
      • Load Balancer Protocol:HTTP Load Balancer Port:80 Instance Protocol:HTTP Instance Port:80
      • 负载均衡器协议:HTTPS负载均衡器端口:443实例协议:HTTP实例端口:80(每个密码由我的证书提供者正确选择,并且SSL字段必定100%正确)

      更多想法:

      话虽如此,我不是用HTTPS进行测试,而是使用普通的HTTP.即使我的证书提供者说SSL设置正确,我也不认为SSL设置正确.我感到可疑的原因是,当我尝试键入 https://app.myapplication.com 时,我得到了Google开发者工具网络"标签中的错误(失败)net :: ERR_CONNECTION_CLOSED".但这应该是不适用的,因为即使使用常规HTTP也会遇到问题.我可以稍后再对SSL进行故障排除.

      That being said, I'm not testing with HTTPS, but normal HTTP instead. I'm not convinced SSL is setup properly even though my certificate provider said it is. The reason I'm suspicious is that when I try to key in https://app.myapplication.com I get the error "(failed) net::ERR_CONNECTION_CLOSED" in Google Developer Tools, in the Network tab. But this should be non-applicable because I'm having the problem even using regular HTTP. I can troubleshoot SSL later.

      重申一下,我的问题是使用某些功能时出现"504 Gateway Timeout"问题,但有时是随机发生而不是加载页面(但很少).仅当使用负载平衡时才会发生此504问题,而直接连接到我的两个实例之一时则不会发生.

      So to reiterate, my problem is having the "504 Gateway Timeout" problem when using some functions, but also occasionally at random instead of loading the page (but rarely). This 504 problem happens ONLY WHEN using Load Balancing, but never when connecting straight to one of my two instances.

      我不知道要问哪个问题,因为我已经将每个文档都跟踪到了T处,所以对所有建议都进行了两次和三次检查,遍及整个网络,什么都没有.

      I don't know which question to ask, because I've Followed every document to the T, double and triple checked all suggestions all over the web and NOTHING.

      推荐答案

      对于我来说,事实证明负载均衡器没有问题.最终的解决方案最终是Ubuntu的hosts文件,其中有一个莫名其妙的条目,用于将流量从某个神秘IP路由到我的应用程序的主机名.因此,在创建PDF的过程中,PDF生成器将重写路径以指向神秘服务器,从而导致网关超时问题.我不知道为什么它偶尔会工作并且不会失败.

      In my case, it turns out that there was no problem with the load balancer. The final solution ending up being Ubuntu's hosts file in which there was an inexplicable entry to route traffic from some mystery IP to my application's host name. So, during the process of creating the PDF, paths were getting re-written by the PDF generator to point at the mystery server, and hence the Gateway timeout issues. I have no idea why it was occasionally working and not failing.

      127.0.0.1 localhost
      127.0.1.1 ubuntu-server
      42.139.126.191 app.myapp.com
      

      这是它的样子,所以我移开了第三行,所有齿轮又开始旋转. :P

      This is what it looked like, so I removed that third line and all the gears started turning again. :P

      这篇关于504网关超时-两个带负载均衡器的EC2实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆