2011-07-12 42 views
3

爲什麼我不能在node.js中使用端口80?當我在node.js中調用listen函數時,端口和ip地址的規則是什麼?哪些是允許的,爲什麼?Node.js端口和號碼的限制

var http = require('http'); 
http.createServer(function (req, res) { 

    res.writeHead(200, {'Content-Type': 'text/plain'}); 
    res.end('Yo'); 

}).listen(80, "127.0.0.1"); 

謝謝!

+1

可能重複的HTTP ://stackoverflow.com/questions/6109089/how-do-i-run-node-js-on-port-80) – vcsjones

回答

6

端口80是受保護的,你需要root權限才能使用它:

sudo node script.js