配置node.js windows 2008服务器 [英] configuration node.js windows 2008 server
问题描述
我已将所有需要的软件包和node.js安装到专用机Windows 2008 Server。
I did install all needed package and node.js to dedicated machine 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/ ,
我得到'Hello World'
但是如果尝试从另一台机器调用此服务:
http://my.domain.ip.address:1337 / Ooops,I看不到什么。
我已经关闭防火墙了
So when I call http://local.host:1337/, I get 'Hello World' But if try to call this service from another machine: http://my.domain.ip.address:1337/ Ooops, I can't see nothing. I already switch Off firewall at all
感谢所有建议
推荐答案
聆听 localhost
或 127.0.0.1
只允许回复同一台计算机对该特定IP或主机名发出的请求。
Listening to localhost
or 127.0.0.1
only allows for responding to requests made from the same computer to that specific IP or hostname.
要让应用程序响应多个IP地址的请求,您需要收听每个IP地址。
To have your application respond to requests for multiple IP addresses, you'll need to listen to each of them. You can either do this individually.
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_ANY
( 0.0.0.0
) ,其在非特定的元地址中。而且,这是 hostname
参数的默认值,因此您只需要指定 port
。
Or, you can listen to IPADDR_ANY
(0.0.0.0
), which in a non-specific, meta address. And, this is the default value for the hostname
argument, so you only need to specify the port
.
http.createServer(function (req, res) {
// ...
}).listen(port);
这篇关于配置node.js windows 2008服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!