Javascript 设置节点使其外部可见?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8325480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set up node so it is externally visible?
提问by flossfan
Newbie question - might be more appropriate for ServerFault, apologies if so.
新手问题 - 可能更适合 ServerFault,如果是这样,请道歉。
I'm setting up node on Ubuntu 11.10, following the excellent howtonode instructions on installing Node.
我正在 Ubuntu 11.10 上设置节点,遵循有关安装 Node的优秀 howtonode 说明。
I can get the Hello World page running on 127.0.0.1:8000, but how do I set it up to appear for my server's external IP?
我可以在 127.0.0.1:8000 上运行 Hello World 页面,但是如何设置它以显示我服务器的外部 IP?
I'm used to configuring Apache - what's the node equivalent of Apache's "Hello World" page?
我习惯于配置 Apache - Apache 的“Hello World”页面的节点等价物是什么?
Thanks for your help.
谢谢你的帮助。
UPDATE: Maybe what I need is a tutorial on hosting Node. Would be great if anyone could suggest a good one.
更新:也许我需要的是关于托管 Node.js 的教程。如果有人能推荐一个好的,那就太好了。
回答by Samyak Bhuta
There is no configuration needed to make your external IP address work with node.js, unless and until you bind it otherwise.
无需配置即可使您的外部 IP 地址与 node.js 一起使用,除非您以其他方式绑定它。
Instead of .listen(PORT, IP_ADDRESS_OR_HOST );
use .listen(PORT);
而不是.listen(PORT, IP_ADDRESS_OR_HOST );
使用.listen(PORT);
Then, just use IP_ADDRESS_OR_HOST:PORT
to access it.
然后,只需使用IP_ADDRESS_OR_HOST:PORT
即可访问它。
回答by Lloyd
You can set up Node to listen on any IP/port, check out http://nodejs.org/docs/v0.6.3/api/http.html#server.listen
您可以将 Node 设置为侦听任何 IP/端口,请查看http://nodejs.org/docs/v0.6.3/api/http.html#server.listen
Or a quick modified example from the link you supplied:
或者您提供的链接中的快速修改示例:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(80, "192.168.1.1");
console.log('Server running at http://192.168.1.1:80/');