I'm using a fresh install of Centos 5.5. I have Node installed and working (I'm just using Node -- no apache, or nginx.), but I cannot figure out how to make a simple server on port 80. Node is running and is listening to port 80. I'm just using the demo app:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(80, "x.x.x.x");
console.log('Server listening to port 80.');
When I visit my IP, it does not work. I obtained my ipaddress using ifconfig. I've tried different ports. So there must be something I am missing.
What do I need to configure on my server to make this work? I would like to do this without installing apache or nginx.
Luke
Edit-- Ok so, I installed nginx and started it up, to see whether or not it is related to node, and I don't see its welcome page. So it definitely has something to do with the server.
Am I retrieving the IP Address correctly by running: ifconfig then reading the inet addr under eth0?
Are you running it as root? Otherwise, you will not be able to bind to port 80.
What happens if you change the port number to something (free) above 1024?
Also, what happens if you specify the IP address to listen on, as in the example here?
As said in my comment the code works (I ran it as root on FreeBSD).
In Linux 127.0.0.1 (aka localhost) is bound to interface "lo". Interface "eth0" should have a different IP-address.
Stop node; turn off nginx (so port 80 is free); put the eth0-address (so not 127.0.0.1) in the above code instead; restart node and try to connect again to port 80 on the other IP-address.
Hint: check with "netstat -ltn" to what IP-address port 80 is bound and try to connect to that address.
don't know if this is still bothering you, however I once ran into kinda the same error on my Debian 6.0: I could connect with a local browser (same machine) using:
However,
from any other computer to the named Debian system resulted in "connection refused". So what I did was to just leave out the ip setting inside my demo code:
hope that helps, that did it for me. Note that I changed the port setting to 8080 because there was another server running on port 80 already.