【问题标题】:node.js http connection works with AWS instance, doesn't work with LoadBalancernode.js http 连接适用于 AWS 实例,不适用于 LoadBalancer
【发布时间】:2019-07-19 00:17:06
【问题描述】:

我正在使用 node.js 和 http 对象连接到具有特殊应用程序服务器的网络服务器。在亚马逊的服务器上运行良好,没问题。

不,我们正在运行经典负载均衡器。工作 - 我可以在我的浏览器中输入 ELB 的 URL,我会看到我们服务器的答案。

但是当我尝试使用我的 node.js 脚本打开相同的 URL 时,我总是会超时。

示例代码:

try {
  console.log( "start test" );
  var http = require("http");

  var options = { host: "test.server.name",
   					      port: "80",
					        path: "/dp/",
   					      headers: {
					    	    'Encoding' : 'BINARY'						    
   					      }         
   					    };	

  console.log( "start get " + options.host );

  http.get( options , function( res ) {
    console.log( "in callback" );
			    
    res.on('data', function(data) {
      console.log( "callback get data " + data );
    });
					
    res.on('end', function() {
      console.log( "callback end" );
    });
			    	
    res.on('error', function(e) {
      console.log( "callback error" );
    });
  } );
} catch( err ) {
  console.log( "error " + err.message );
}

代码直接与服务器一起工作。 使用负载均衡器时不起作用。

我必须知道该怎么做 - 有什么想法吗?

【问题讨论】:

  • 请求超时,或者您收到指示(408 请求或 504 网关)超时的响应?
  • 你的负载均衡器的安全组是什么?
  • @SébastienStormacq - 负载均衡器的安全组与 aws 实例相同,所有需要的端口均已打开。
  • @jarmod - 错误消息是:'Error: connect ETIMEDOUT 3.120.18.198:80' in Object.exports._errnoException (util.js:734:11)跨度>
  • 附加信息:我让一位客户在他的机器上尝试这个 - 不同的互联网连接,不同的设置(和另一个国家)。同样的问题。所以它不在我的网络和/或防火墙配置中!

标签: node.js amazon-web-services http get amazon-elb


【解决方案1】:

我明白了。不知道为什么 - 但问题出在我们使用的代理上。

我发现了这个: How can I use an http proxy with node.js http.Client? 并且通过使用我们的代理它起作用了......

【讨论】:

    【解决方案2】:

    我找到了——它是代理。

    我使用这个设置代理: How can I use an http proxy with node.js http.Client? 和这个: https://www.vanamco.com/2014/06/24/proxy-requests-in-node-js/

    现在可以使用了!

    【讨论】:

      猜你喜欢
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 2021-06-18
      • 2017-05-23
      相关资源
      最近更新 更多