配置的node.js的Windows 2008服务器(configuration node.js w

2019-10-30 04:45发布

我做了所有需要的包和node.js的安装到专用机的Windows 2008服务器。

 var http = require('http');
 var port = 1337;
 http.createServer(function (req, res) {
      res.writeHead(200, {'Content-Type': 'text/plain'});
      res.end('Hello World\n');
 }).listen(port, '127.0.0.1');
console.log('Server running at http://127.0.0.1:' + port );

所以,当我打电话http://local.host:1337/ ,我得到的“Hello World”但是,如果试图从另一个调用本机服务: HTTP://my.domain.ip.address:1337 /哎呀,我可以“看不到什么。 我已经转关防火墙在所有

谢谢,所有建议

Answer 1:

localhost127.0.0.1只允许用于响应来自同一台计算机特定IP或主机名的请求。

要拥有多个IP地址的请求的响应应用程序,你需要倾听他们每个人。 你可以单独做到这一点。

function server(req, res) {
    // ...
}

http.createServer(server).listen(port, '127.0.0.1');
http.createServer(server).listen(port, 'my.domain.ip.address');
http.createServer(server).listen(port, '<any other public facing IP address>');

或者,你可以听IPADDR_ANY0.0.0.0 ),它在非特定,元地址。 而且,这是为默认值hostname的说法,所以你只需要指定port

http.createServer(function (req, res) {
    // ...
}).listen(port);


文章来源: configuration node.js windows 2008 server