【问题标题】:configuration node.js windows 2008 server配置node.js windows 2008 server
【发布时间】:2013-09-07 22:41:53
【问题描述】:

我确实将所有需要的包和 node.js 安装到专用机器 Windows 2008 Server。

 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/, 我得到“你好世界” 但如果尝试从另一台机器调用此服务: http://my.domain.ip.address:1337/ 哎呀,我什么也看不见。 我已经完全关闭了防火墙

感谢所有建议

【问题讨论】:

  • 你通常会在另一台服务器后面部署节点,如果性能不是一个大问题,最简单的方法是将它放在 IIS 后面,如果你得到 WebMatrix,它带有内置配置文件如果您创建一个 Node 项目,那(我只是不知道它们在哪里可以在线获得)。

标签: windows node.js configuration


【解决方案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>');

或者,您可以listen to IPADDR_ANY (0.0.0.0),它位于一个非特定的元地址中。而且,这是hostname 参数的默认值,因此您只需指定port

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

【讨论】:

    猜你喜欢
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 2021-01-13
    相关资源
    最近更新 更多