Question simplified
I can do curl {publicip}:4321
but not curl {publicip}:80
or curl {publicip}
. But from the server's ssh, i can run curl {privateip}:80
and curl localhost:80
without any issues. And also, both port 80 and port 4321 are added to inbound rules in security group. Why is that happening?
The Story
I'm new to AWS EC2. I recently created an EC2 t4g nano instance, and ran a NodeJS server using PM2. The server listens on port 4321. Then using iptables, I redirected port 80 to port 4321. Then in security groups, I added inbound rule from "Anywhere IP" to port 80 (HTTP).
Everything was working, I was able to connect using the instance's public IP to the server until today morning, when I suddenly wasn't able to even SSH to the server. The instance status in AWS console showed as 'running', but in status check, 1/2 was not successfull. It showed "Instance reachability failed". Then, I tried to restart the instance, it worked and then I could SSH it.
Now, I restarted PM2, and then again added the redirecting rule to iptables. But now, I cant connect to port 80 using public IP.
I can run curl localhost:80
and curl {privateip}:80
, it connects without any issues. When I run curl {publicip}:80
or curl {publicip}
it shows 'Connection refused`. As I said, port 80 already exists in the security group's inbound rules.
I added port 4321 to the inbound rules of the security group, and I can connect without any issues using curl {publicip}:4321
but not curl ${publicip}:80
. How's that possible? Did I miss something?