无法连接到节点的端口错误

当我跑步

node app.js 

我得到这个错误

  info - socket.io started warn - error raised: Error: listen EACCES 

这是应用程序中的所有JavaScript代码。

当我跑步

 sudo supervisor app.js 

它输出

 DEBUG: Starting child process with 'node app.js' 

但是当我访问本地主机:8080,它说谷歌无法连接到本地8080.我设置端口client.js下面(第3行)。

你能看到我做错了吗?

app.js

 var express = require('express'); var app = express(); var http = require('http'); var server = http.createServer(app); var jade = require('jade'); app.configure(function(){ app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(__dirname + '/public')); app.set('port', 80); app.set('views', __dirname + '/views'); app.engine('jade', require('jade').__express); }); var io = require('socket.io').listen(app.listen(app.get('port'))); app.get('/', function(req, res){ res.render('layout.jade'); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); }); var socketClient = require('socket.io-client'); var socket = socketClient.connect('https://chat.meatspac.es'); socket.on('message', function(data) { io.sockets.emit('newmeat', { meat: data }); }); 

client.js

 (function($) { var socket = io.connect('http://localhost:8080'); var template = $('#template').html(); socket.on('newmeat', function (data) { var copy = $(template).clone(); var list = $('#meats'); var images = $('img'); if (images.length < 9) { // search for empty images, fill them with new data if ($('[data-empty]').length > 0) { $('[data-empty]').first().attr('src', data.meat.chat.value.media).removeAttr('data-empty'); return; } // otherwise fill the template in with data copy.find('img').attr({ 'src' : data.meat.chat.value.media, 'height' : '150', 'width' : '200' }); // if the image is the 4th one appended (counting from zero), create the meatspace logo if (images.length == 3) { list.append(copy); var template2 = $(template).clone(); template2.find('img').addClass('logo').attr({ 'src' : '/meatspace.svg', 'height' : '150', 'width' : '200' }); template2.find('a').addClass('logolink'); list.append(template2); } else { list.append(copy); } } // else add new data to elements already present else if ($('[data-empty]').length > 0) { $('[data-empty]').first().attr('src', data.meat.chat.value.media).removeAttr('data-empty'); return; } }); // remove an unwanted gif $('ul').on('click', 'a:not(:eq(4))', function(e) { e.preventDefault(); $(e.currentTarget).find('img').attr({'src' : '', 'data-empty' : ''}); }); }(jQuery)); 

在很多* nix机器上,除非你用sudo(你不想运行你的代码)提升,否则你不能绑定到端口80。

一种解决scheme是在1024以上的端口上运行它,然后使用一个反向代理,如节点http-proxy或nginx,它们监听80和转发。

这也有其他的好处,例如只需转发到不同端口上运行的不同节点应用程序,就可以在80个地址上(通过不同的主机名)对多个站点进行寻址。

我在这篇文章中有一些链接: NodeJS托pipe托pipevs VPS