2013-03-05 145 views
0

我最近购买了Fujitsu服务器。我正在运行Linux Mint(Cinnamon)。无法在端口80上运行节点服务器

我安装了Node.js,没有问题,并且可以在80以外的任何可用端口上运行我的服务器脚本。起初,它响应EACCES错误,但是当我以root身份运行node.js时,远。现在它输出的结果与我在任何其他端口上运行它一样,但当我进入域时不会工作。

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); 
} 

然命令行中壳为:

/home/xymon/node/node server.js 
ス登录后

我的代码可以在我试过的任何其他端口上运行。甚至81.不是80,它把我拉上了墙。

+0

是否仍然运行脚本的旧过程?如果正在运行一个旧的进程端口80仍在使用中。查看您的进程列表(ps aux)是否运行脚本的旧实例。 – Cromax 2013-03-05 13:08:15

+0

如果你不想使用nginx或httpproxy,这个答案可能很有用。 http://stackoverflow.com/a/6848861/1349025 – thtsigma 2013-03-05 13:12:10

+0

有没有其他的节点运行的实例...有没有办法看到进程列表和他们正在使用的端口?我知道我在购买fujitsu之前在windows上运行我的服务器时必须更改skype的端口......我对linux的世界相当陌生。 – Xymon 2013-03-05 13:13:11

回答

2

一个选项是作为sudo运行,这不是一个好的选择,因为你所有的站点代码都会被提升。

另一种选择是在备用端口上运行该站点,并将其放在nginx或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); 

这也具有能够运行在端口80多个站点,你可以看到漂亮的好处,我也可以做端口3000,但只能在本地网站。

1

善良,多么冒险!

我已经通过以下步骤解决了问题。

  1. 打开端口80 - 100
  2. 在端口100
  3. 运行服务器Redirrecting口80〜100 ... 的iptables -t NAT -A PREROUTING -p tcp的--dport 80 -j REDIRECT - 对端口100
  4. 在sudo中运行Node.js。

谢谢大家的帮助,这是一个为期两天的运行,但我正在学习!

完成的产品:http://io-chat.com/home

相关问题