0

I created a new instance, added the same security groups as before in EC2, selected the same VPC as before (everything exactly the same afaik), but now I get: ERR_CONNECTION_REFUSED when I try to connect to port 8080

I have a simple nodejs server running on port 8080:

netstat -anp | grep :8080
   (Not all processes could be identified, non-owned process info
    will not be shown, you would have to be root to see it all.)
   tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      2438/node

This: sudo lsof -i outputs:

COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhclient  640   root    5u  IPv4   9825      0t0  UDP *:bootpc
dhclient  640   root   20u  IPv4   8531      0t0  UDP *:15190
dhclient  640   root   21u  IPv6   8532      0t0  UDP *:13517
sshd      950   root    3u  IPv4  10114      0t0  TCP *:ssh (LISTEN)
sshd      950   root    4u  IPv6  10116      0t0  TCP *:ssh (LISTEN)
sshd     1140   root    3u  IPv4   1708      0t0  TCP ip-x-x-x-x.eu-west-1.compute.internal:ssh->x-x-x-x:49442 (ESTABLISHED)
sshd     1194 ubuntu    3u  IPv4   1708      0t0  TCP ip-x-x-x-x.eu-west-1.compute.internal:ssh->x-x-x-x:49442 (ESTABLISHED)
node     1800 ubuntu   12u  IPv6  10541      0t0  TCP *:8545 (LISTEN)
node     2438 ubuntu   16u  IPv4  12327      0t0  TCP localhost:http-alt (LISTEN)

And: sudo netstat -tulpn

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      2438/node
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      950/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      950/sshd
tcp6       0      0 :::8545                 :::*                    LISTEN      1800/node
udp        0      0 0.0.0.0:15190           0.0.0.0:*                           640/dhclient
udp        0      0 0.0.0.0:68              0.0.0.0:*                           640/dhclient
udp6       0      0 :::13517                :::*                                640/dhclient

I'm totally at a loss here.

I tried restarting the instance multiple times, re-adding a security group, nothing helps.

The ERR_CONNECTION_REFUSED tells me that it exists, but the port forwarding is not applied.

BlockChange
  • 103
  • 2

2 Answers2

1

Your nodejs server is listening to the local loopback device 127.0.0.1 as you can see in the netstat output. 127.0.0.1:8080

You need to change the nodejs server to listen to 0.0.0.0

Henrik Pingel
  • 9,380
  • 2
  • 28
  • 39
  • Weird, any idea how to change that? Because locally it works, and this has worked before on another instance (still does) without any of that. – BlockChange Jul 14 '16 at 14:04
  • That can't be ... If a service is listening to 127.0.0.1 you cant access it from outside. Maybe you got a proxy server in front of the nodejs server on your old instance? – Henrik Pingel Jul 14 '16 at 14:15
  • I've made an AMI of the working instance, and launced a new instance of that, still not working.. – BlockChange Jul 14 '16 at 14:41
0

Turns out it was a problem with the nodejs server, I had to expose it to external requests. Since it was working on localhost I did not think it would be a problem.

So something like this:

   app.listen(8080, '0.0.0.0', (err) => {
   ...

The 0.0.0.0 makes sure it also responds to external IPs.

BlockChange
  • 103
  • 2