Port won’t open on new EC2/AWS instance

amazon ec2amazon-web-servicessecurity-groups

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.

Best Answer

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