我用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制作服务器吗?
您能解释一下为什么其他计算机无法访问我的节点js服务器吗?
配置您的应用程序以在上运行0.0.0.0
:
// basicServer.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World');
}).listen(1337, '0.0.0.0');
现在,您可以使用IP进行访问了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句