只能从机器运行服务器访问Express Node.js服务器

我使用快递有一个新手问题。 我正在使用Ubuntu 14.04并创build一个新的目录并在terminal中运行“express”,并设置了一个项目模板。 然后运行“npm install”安装依赖关系。 然后编辑'views / layout.jade'来改变“!!!” 到“doctype的html”作为节点错误时build议尝试运行服务器没有改变。

之后,我通过在terminal上input“node app.js”启动服务器,然后使用“localhost:3000”或“192.168.1.13:3000”在浏览器中看到默认页面。

我的理解是,我应该能够使用“192.168.1.13:3000”从本地networking中的另一台计算机。 然而,当我尝试这个“连接到192.168.1.13 …”大约30秒到一分钟,然后它说:“连接超时…服务器在192.168.1.13是花了很长的时间来回应。

我已经尝试了这两个Windows桌面和Android手机上的Firefox和铬。 我也试着把它设置到80端口,而不是3000结果相同。 我已经尝试在app.listen中添加“0.0.0.0”,但是这个结果也是一样的。

在这个Ubuntu安装中,我从来没有设置过防火墙或端口转发,所以我相信这些不应该成为问题? (是我的路由器的问题?)也许我错了。

这里是相关的文件 –

app.js:

/** * Module dependencies. */ var express = require('express') , routes = require('./routes'); var app = module.exports = express.createServer(); // Configuration app.configure(function(){ app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(__dirname + '/public')); }); app.configure('development', function(){ app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function(){ app.use(express.errorHandler()); }); // Routes app.get('/', routes.index); app.listen(3000, function(){ console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); }); 

路线/ index.js:

 /* * GET home page. */ exports.index = function(req, res){ res.render('index', { title: 'Express' }) }; 

意见/ layout.jade:

 doctype html html head title= title link(rel='stylesheet', href='/stylesheets/style.css') body!= body 

意见/ index.jade:

 h1= title p Welcome to #{title} 

让我知道,如果我已经离开了任何东西。 干杯。

我解决了这个问题,用slebetmanbuild议的iptables打开传入端口3000,使用以下命令:

 iptables -I INPUT 1 -p tcp --dport 3000 -j ACCEPT