2

I know there are lots of resources on this topic, but I think I've done everything correctly and I still can't connect to my server.

I've started a simple node.js server on port 80.

sudo netstat -tnlp | grep 80
tcp        0      0 127.0.0.1:80            0.0.0.0:*               LISTEN      3657/node   
curl localhost:80
Welcome Node.js

I've configured the Security group for this instance as well as the VPC to allow traffic. security rules

I've made sure there is no local firewall and that the VPC ACL is not blocking traffic (not that I expected it, since this is a completely new instance.)

service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.

The output when I try to connect from my local machine:

 curl 3.xxx.xxx.xxx
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:03 --:--:--     0
curl: (7) Failed to connect to 3.xxx.xxx.xxx port 80: Connection refused

Are there any other ideas on what to check next?

HAL
  • 381
  • 1
  • 2
  • 13
  • 1
    It's interesting that that says "connection refused" when trying to connect from your local machine - would suggest to me that the request is reaching your EC2 instance and then being refused there perhaps. At a guess, maybe your node isn't configured to connect to external clients... https://stackoverflow.com/questions/14043926/node-js-connect-only-works-on-localhost – Jack Apr 27 '21 at 04:05
  • on which port you have started your node js server, is it 80 or something else like 3000?check your app.js and check on which port your server is listening – Jatin Mehrotra Apr 27 '21 at 04:08
  • 1
    Your app is likely running on 3000. – Rivers Apr 27 '21 at 04:08
  • The netstat command and `curl localhost` command are intended to show that it is running on port 80 on the EC2 instance. – HAL Apr 27 '21 at 04:13
  • 1
    @Jack Thank you! That was the problem. You can write an answer which I will accept, or if you don't I will write an answer with some more details. – HAL Apr 27 '21 at 04:18
  • I might leave it to you to answer - it'll probably be more useful for other viewers to have more details :-) Glad I could help! – Jack Apr 27 '21 at 04:58

1 Answers1

1

The answer to my problem was https://stackoverflow.com/a/14045163/2369000. The boilerplate code that I copied used a method to only listen to requests that originated from localhost. This could have been detected from the netstat output, which said 127.0.0.1:80 for the listening address. The answer was to use .listen(80, "0.0.0.0") or just .listen(80) since the default behavior is to listen for requests from any IP address.

HAL
  • 381
  • 1
  • 2
  • 13