问题
My node application is listening to port 8080. When I add
app.listen(port,'50.30.217.289');
I can access the application from the browser. But when I replace the IP address with the Elastic IP address of my EC2 instance, I get an error :
EADDRNOTAVAIL
How do I fix this ?
回答1:
What you are trying to do is not how it works in EC2.
The public IP address is mapped to the primary private IP address through network address translation (NAT).
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html
If you examine your network interfaces on the machine, you won't find any public IP addresses on them. The public IP addresses are translated onto the private addresses at the Internet gateway. This is done automatically with no configuration needed, for instances with public IP addresses.
To bind a service to a specific public address, you bind it to the matching private IP address on the instance itself.
回答2:
EADDRNOTAVAIL
means your EC2 instance does not have a network interface that has that IP address assigned, so you cannot start listening on it.
来源:https://stackoverflow.com/questions/34711564/eaddrnotavail-while-using-ec2-instance-only