Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I run the basic example on my Amazon EC2 Server, I get the message "Server running" in the console. But if I try to open it in a browser, using my elastic IP + the port, I get no result.

I think I have opened the TCP ports 22 and 1337 (I'm not a 100% sure because I'm new to this stuff).

share|improve this question
up vote 5 down vote accepted

Presumably you mean this example:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, "");
console.log('Server running at');

The message you would have received like so is Server running at - the emphasized part is key here, i.e. the server has been configured to listen on the IP address (aka localhost) only, whereas you are trying to browse it via your elastic IP address.

Accordingly, you can achieve you goal by replacing in the listen()statement with the private/internal IP address which has been assigned to your EC2 instance.


Alternatively, you could use the public/external DNS name instead, which exhibits a lesser known dynamic IP address resolution depending on the origin of the DNS query, see e.g. Why do I have two IP addresses and two host names?:

The external DNS name (which looks like resolves to the public IP address of the instance outside the Amazon EC2 network and the private IP address from within Amazon EC2 network.

Finally (as per cyberx86's comment, thanks!), you may be able to omit the optional address parameter altogether (but see below), see server.listen(port, [hostname], [callback]):

If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

Be aware though, that this might not always be the right thing in advanced scenarios, insofar there may be more than one network interface available in fact after the recent introduction of Elastic Network Interfaces (ENI) in the Virtual Private Cloud (VPC), which is giving you the ability to create additional ENIs, and to attach a second ENI to an instance (again, this is within the VPC).

share|improve this answer
oh that makes sense. If I replace it with my elastic IP I receive the error: "Error: listen EADDRNOTAVAIL" - does this mean that the port is not open? – Christian Strang Jan 31 '12 at 12:43
@Christian: sorry, I mixed this up in the hurry - you'll have to use the internal IP address, which AWS automatically assigned to your EC2 instance on startup (the routing/wiring from the external to the internal address is done automatically by AWS on your behalf); you can inspect it manually e.g. on the properties window of your instance in the AWS Management Console, or by various other means for automation purposes. – Steffen Opel Jan 31 '12 at 12:48
Great! Replacing it with my "Internal IP" made it work. For everyone who doesn't know where to find it, it's listed under "Private DNS" in your instance description. Use your internal ip for the listen statement and your elastic ip to "call" your server. – Christian Strang Jan 31 '12 at 12:51
@ChristianStrang: You should be able to simply omit the address altogether, to have nodejs listen on all (local and external) addresses - i.e.: http.createServer(...).listen(1337); This may be practical since there is only one external interface, and your internal-ip may change. – cyberx86 Jan 31 '12 at 13:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.