【发布时间】:2016-07-21 16:58:28
【问题描述】:
我用 node.js 做了一个服务器,如下所示:
// basicServer.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
它在我的 Mac 上工作,我可以访问。但是,我的并行窗口无法访问。
当然,其他电脑也可以。
我应该用 apache 还是 NGINX 做服务器?
能否解释一下为什么其他电脑无法访问我的node js服务器?
【问题讨论】:
-
如果其他计算机连接在局域网中或者如果您有公共 ip,它将显示给其他计算机,请注意,如果您有公共 ip,您可能需要编写您的 ip 代码而不是 127.0.0.1浏览器,但前提是您未在局域网中连接
-
您也可以使用您的机器名称。喜欢。 //我的机器名:1337
标签: javascript node.js nginx