Question

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
Was it helpful?

Solution

Don't know what's wrong with your sample. Here is my sequence of steps which works:

  1. Create 'Extra Small' Ubuntu Server 13.10 instance in WestUS. (NEW->Virtual Machine->Quick Create)
  2. Add endpoint HTTP 80 -> 80 (Endpoints->Add->Add New Standalone Endpoint->HTTP,TCP,80,80)
  3. Install nodejs (sudo apt-get install nodejs). This installs version 'v0.10.15'
  4. Create server.js with your code.
  5. Start nodejs server (sudo nodejs server.js)

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

OTHER TIPS

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.

With azure you need to use the environment variable process.env.PORT to set the port. If on localhost you want to use the 80, a good way to set it in your code in this way as recommended here:

server.listen(process.env.PORT || 80);

However, be sure, if you run a VM on Azure, that the windows firewall is correctly set.

I believe your port is not allowing remote connection on port 80 as you can get into the ubuntu VM using ssh tunneling from outside. Try this answer . Though it's apache related , but this two problem looks alike and it's actually identical. Try this out.

In the mean time , best of luck. Fingers crossed :p

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top