2017-04-26 43 views
0

我有开始这样的socket.io节点文件...运行在节点sockets.io没有sudo访问

//sockets/server 
var app = require('http').createServer(handler) 
var io = require('socket.io')(app); 
var fs = require('fs'); 
app.listen(80); //the 5th line that the error refers to 

当我从“节点myFile.js”控制台运行我得到的以下错误......

events.js:85 
     throw er; // Unhandled 'error' event 
      ^
Error: listen EACCES 
    at exports._errnoException (util.js:746:11) 
    at Server._listen2 (net.js:1112:19) 
    at listen (net.js:1155:10) 
    at Server.listen (net.js:1240:5) 
    at Object.<anonymous> (/home/myUser/node/myFile.js:5:5) 
    at Module._compile (module.js:460:26) 
    at Object.Module._extensions..js (module.js:478:10) 
    at Module.load (module.js:355:32) 
    at Function.Module._load (module.js:310:12) 
    at Function.Module.runMain (module.js:501:10) 

我可以很容易地在我的本地机器(毫安)上的错误,加入“须藤”到命令的开始,但我的托管服务提供商不会让我这样做对生产环境。

有没有人有任何想法来解决这个错误(或者甚至知道它是什么意思),而不是把它做成它?

+1

可能的复制http://stackoverflow.com/questions/9164915/node-js-eacces-error-when-listening-on -most-ports) –

+0

谢谢本 - 你是对的 - 不知道我怎么没有找到那篇文章,但它确实描述了正确完成工作的正确方法(正如下面由Tatsuyuki发表的答案那样很快就会接受)。 – d3wannabe

+0

您还可以在不需要更高权限的较高号码端口上运行服务器(这使您不必为您的服务器提供root权限),然后使用iptable配置将端口80重定向到较高的端口号。我在Raspberry Pi上这样做是为了不必为我的服务器进程提供更高的权限,但它可以成功地为端口80服务。 – jfriend00

回答

0

端口80是一个特权端口,您需要rootCAP_NET_ADMIN来绑定它。

的解决方案是:

  1. 不绑定到端口80的发展。

  2. 配置您的系统以允许端口用作普通用户。请参阅:https://superuser.com/questions/710253/allow-non-root-process-to-bind-to-port-80-and-443

[大多数端口上侦听时的Node.js EACCES错误](的
+0

哇,垃圾邮件downvoter :( –

+0

是的,那么你得到我的upvote - 谢谢你的答案 - 我选择了8080,它完美的工作 - 很快就会接受答案...... – d3wannabe