0

I recently purchased a Fujitsu server. I am running Linux Mint ( Cinnamon ) on it.

I installed Node.js with no problem, and can run my server script on any tried port other than 80. At first, it responded with an EACCES error, but when i ran node.js as root, that error went away. Now it outputs the same as if i was running it on any other port, but just won't work when i go to the domain.

var http = require('http');

http.createServer(server).listen(80);

function server(req, res) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.end('Hello World\n');


    console.dir(req);
}

Ran command-line in shell as:

/home/xymon/node/node server.js

after su login.

My code works on pretty much any other port i've tried. even 81. JUST NOT 80, and it's driving me up a wall.

bryanmac
  • 38,941
  • 11
  • 91
  • 99
Xymon
  • 73
  • 1
  • 1
  • 10
  • Is there still running an old process of your script? If there is running an old process port 80 is still in use. Look in your process list (ps aux) if there is running an old instance of your script. – Didatus Mar 05 '13 at 13:08
  • This answer may be useful if you don't wish to use nginx or httpproxy. http://stackoverflow.com/a/6848861/1349025 – thtsigma Mar 05 '13 at 13:12
  • There are no other instances of node running... is there a way to see a list of processes and what port they are using? I know i had to change skype's port when running my server on windows before i purchased the fujitsu... I am fairly new to the world of linux. – Xymon Mar 05 '13 at 13:13
  • @thtsigma I have already tried that method and it did nothing for me. – Xymon Mar 05 '13 at 13:14
  • 1
    You can use `sudo lsof -i tcp:80` to see if there's another process listening on port 80 (it sounds as if there is). – robertklep Mar 05 '13 at 13:58

2 Answers2

2

One option is to run as sudo which isn't a great option since all of you're sites code will be elevated.

Another option is to run the site on an alternate port and put it behind nginx or httpproxy.

var proxyPort = 80;
var http = require('http');
var httpProxy = require('http-proxy');

var options = {
    router: {
        'localhost': '127.0.0.1:3000',
        'site1.com': '127.0.0.1:3000',
        'site2.com': '127.0.0.1:4000'
    }
};
console.log('Proxy Routing:')
console.log(options);
console.log();

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(proxyPort);
console.log('Proxy listening on port ' + proxyPort);

This also has the nice benefit of being able to run multiple sites under port 80. as you can see, I also make the site available on port 3000 but only locally.

bryanmac
  • 38,941
  • 11
  • 91
  • 99
1

Goodness, What an adventure!

I have solved the problem with the following steps.

  1. Opening Ports 80 - 100.
  2. Running Server on Port 100.
  3. Redirrecting port 80 to 100... iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 100
  4. Running Node.js in sudo.

Thank you all for your help, this has been a two-day run around for me but i'm learning!

Finished product: http://io-chat.com/home

Xymon
  • 73
  • 1
  • 1
  • 10