EC2托管的Node.js应用程序 - 不能远程连接到端口连接到、端口、应用程序、Node

2023-09-11 09:13:52 作者:会哭但不会认输

更新:原来,唯一的问题是,我是一个防火墙阻塞某些端口的背后,而不是8000

Update: Turns out the only problem was that I was behind a firewall that blocked some ports, but not 8000.

编辑: TL; DR:不能连接到远程端口9000,但8000端口就可以了,我不知道为什么:(

TL;DR: can't connect to port 9000 remotely, but port 8000 is ok and I don't know why :(

我这有Node.js的多数民众赞成在端​​口上运行的应用程序的 8000 和另一个(的 HTTP代理)端口上运行的 9000

I've got this node.js application that's running on port 8000 and another one (http-proxy) running on port 9000.

在我的机器上运行他们是好的,但我有一些问题,当我把他们的服务器上( EC2 实例 - 我没有在Web控制台安全组打开端口 [ 1] )。该应用程序工作正常,但我无法从外部连接到代理。我试图 $远程登录本地主机9000 在服务器上,并将其连接,所以我想这是个好兆头。

Running them on my machine is fine, but I have some problems when I put them up on a server (EC2 instance - I did open the ports in the web console security group[1]). The application works fine, but I can't connect to the proxy from outside. I tried to $ telnet localhost 9000 on the server and it connects, so I guess that's a good sign.

这是我注意到的另一件事是,如果我尝试单独运行的应用程序,我得到了相同的结果,即:8000 - 确定,9000 - NOTOK:其中;. 不过,如果我更改代理使用的端口,从9000到8000,它的工作原理。如果我交换机的端口上,即应用:9000和代理:8000,我可以连接到代理服务器,而不是应用程序。我也尝试过其他的数字,但不会解决它的。

Another thing that I have noticed is that if I try to run the applications separately, I get the same results, i.e.: 8000 - OK, 9000 - NOTOK :<. However, if I change the port the proxy uses from 9000 to 8000, it works. And if I switch the ports, i.e. application:9000 and proxy:8000, I can connect to the proxy, but not to the application. I have also tried other numbers, but that wouldn't fix it either.

我想有一些非常愚蠢的无关的应用程序本身,而我错过,但我不能把我的手指上,所以没有任何人有任何想法,为什么这种设置不起作用?

I guess there's something really stupid that has nothing to do with the application itself and that I'm missing, but I can't put my finger on it, so does anyone have any idea why this setup doesn't work?

server.js

var express = require('express.io');
var app = module.exports = express();

require('./proxy');

app.http().io();
app.listen(8000);
// ...

的proxy.js

var httpProxy = require('http-proxy');
var url = require('url');

httpProxy.createServer(function(req, res, proxy) {

    // ... 
    proxy.proxyRequest(req, res, {
        host: destination.host,
        port: 80
    });

}).listen(9000);

$ netstat的-pln | grep的节点输出

tcp   0      0      0.0.0.0:9000    0.0.0.0:*       LISTEN  1487/node
tcp   0      0      0.0.0.0:8000    0.0.0.0:*       LISTEN  1487/node

安全组的规则

推荐答案

原来,这个问题是不是在所有相关的应用程序或EC2实例安装。

It turned out that the problem was not at all related to the application or the EC2 instance setup.

我在测试这被阻塞某些端口的网络。这就是为什么当移动代理端口 8000 它工作正常,但在 9000 或任何其他随机那些我试了一下是不是。 D'哦!

The network I was in while testing this was blocking some ports. This is why when moving the proxy to port 8000 it was working fine, but on 9000 or any other random ones that I tried it wasn't. D'oh!

 
精彩推荐
图片推荐