Reputation: 10864
Newbie question - might be more appropriate for ServerFault, apologies if so.
I'm setting up node on Ubuntu 11.10, following the excellent howtonode instructions on installing Node.
I can get the Hello World page running on 127.0.0.1:8000, but how do I set it up to appear for my server's external IP?
I'm used to configuring Apache - what's the node equivalent of Apache's "Hello World" page?
Thanks for your help.
UPDATE: Maybe what I need is a tutorial on hosting Node. Would be great if anyone could suggest a good one.
Upvotes: 18
Views: 40736
Reputation: 874
You have to ensure that the designated port (8000) is open to reach.
iptables -L INPUT -v
or ufw status verbose
to see if that port 8000 is openiptables -I INPUT -p tcp -m tcp --dport 8000-j ACCEPT
or ufw allow 8000
iptables -L INPUT --line-numbers
or ufw status verbose
Upvotes: 0
Reputation: 1254
There is no configuration needed to make your external IP address work with node.js, unless and until you bind it otherwise.
Instead of .listen(PORT, IP_ADDRESS_OR_HOST );
use .listen(PORT);
Then, just use IP_ADDRESS_OR_HOST:PORT
to access it.
Upvotes: 21
Reputation: 29668
You can set up Node to listen on any IP/port, check out http://nodejs.org/docs/v0.6.3/api/http.html#server.listen
Or a quick modified example from the link you supplied:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(80, "192.168.1.1");
console.log('Server running at http://192.168.1.1:80/');
Upvotes: 3