I've got an Ubuntu virtual machine on Azure. I added an enpoint in the azure management portal:
NAME PROTOCOL PUBLIC PORT PRIVATE PORT LOAD-BALANCED SET
---------------------------------------------------------------
HTTP TCP 80 80 -
And I tried to listen to it:
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);
It works if I ssh in and curl it:
$ curl localhost:80
Hello World
But if I try to access it by subdomain.cloudapp.net
, nothing comes back. It also doesn't return anything when accessed by public ip address.
Which port and address should I listen on with my node application to access it from the outside world?
Do I need another azure service to be able to access the VM?
How would I enable public access if it's a problem with the firewall?
Edit:
I checked if there was a firewall, but there isn't:
$ sudo ufw status
[out :: subdomain.cloudapp.net] Status: inactive
Edit 2:
Provisioned a different ubuntu vm, but it still doesn't work. Tried to restart iptables, but no service was known:
$ sudo service iptables restart
iptables: unrecognized service
The iptables are:
$ 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
You open a port, or create an endpoint, to a virtual machine (VM) in Azure by creating a network filter on a subnet or a VM network interface. You place these filters, which control both inbound and outbound traffic, on a network security group attached to the resource that receives the traffic.
In the network interface properties, select IP configurations in Settings. Select ipconfig1 in the IP configurations page. Select Static in Assignment. Select Save.
Don't know what's wrong with your sample. Here is my sequence of steps which works:
I'm able to connect remotely via ndtest2.cloudapp.net name(already deleted) and get "Hello World".
EDIT: However I cannot connect to the version built from sources. But I can connect if I download binaries from http://nodejs.org
You are probobly listening on 127.0.0.1
, or local host. You need to be listening on 0.0.0.0
, to fix this, replace
server.listen(80);
with
server.listen(80, "0.0.0.0")
Just to clarify, 0.0.0.0
is not an acutal address, it means all addresses, 127.0.0.1 and any other IPs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With