我在 Azure 上有一个 Ubuntu 虚拟机。我在 azure 管理门户中添加了一个 enpoint:
NAME PROTOCOL PUBLIC PORT PRIVATE PORT LOAD-BALANCED SET
---------------------------------------------------------------
HTTP TCP 80 80 -
我试着听听:
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
server.listen(80);
如果我 ssh 并 curl 它,它就会起作用:
$ curl localhost:80
Hello World
但是,如果我尝试通过 subdomain.cloudapp.net
访问它,则什么也没有返回。当通过公共(public) IP 地址访问时,它也不会返回任何内容。
我应该使用 Node 应用程序监听哪个端口和地址才能从外部世界访问它?
我是否需要另一个 Azure 服务才能访问虚拟机?
如果防火墙有问题,我该如何启用公共(public)访问?
<小时/>编辑:
我检查了是否有防火墙,但没有:
$ sudo ufw status
[out :: subdomain.cloudapp.net] Status: inactive
编辑2:
配置了不同的 ubuntu 虚拟机,但它仍然无法工作。尝试重新启动 iptables,但没有已知服务:
$ sudo service iptables restart
iptables: unrecognized service
iptables 是:
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootpc
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
最佳答案
不知道您的样本有什么问题。 这是我的有效步骤序列:
- 在 WestUS 中创建“超小型”Ubuntu Server 13.10 实例。 (新->虚拟机->快速创建)
- 添加端点 HTTP 80 -> 80(端点 -> 添加 -> 添加新的独立端点 ->HTTP,TCP,80,80)
- 安装nodejs(sudo apt-get install nodejs)。这将安装版本“v0.10.15”
- 使用您的代码创建 server.js。
- 启动nodejs服务器(sudo nodejs server.js)
我可以通过 ndtest2.cloudapp.net 名称(已删除)远程连接并获取“Hello World”。
编辑: 但是我无法连接到从源代码构建的版本。 但如果我从 http://nodejs.org 下载二进制文件,我就可以连接
关于node.js - Node 要监听azure ubuntu vm的端口/IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19551784/