EC2 hosted Node.js application - can't remotely connect to port

陌路散爱 提交于 2019-12-12 11:04:48

问题


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


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


I've got this node.js application that's running on port 8000 and another one (http-proxy) running on port 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.

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 node output

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

Security group rules


回答1:


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

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!



来源:https://stackoverflow.com/questions/14288567/ec2-hosted-node-js-application-cant-remotely-connect-to-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!