HAL
HAL

Reputation: 451

Connection refused with a basic HTTP server on AWS EC2

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?

Upvotes: 2

Views: 1782

Answers (1)

HAL
HAL

Reputation: 451

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.

Upvotes: 1

Related Questions