Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node which port / ip address to listen to for azure ubuntu vm

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
like image 857
AJcodez Avatar asked Oct 23 '13 20:10

AJcodez


People also ask

How do I access my port on Azure VM?

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.

How do I assign an IP address to an Azure VM?

In the network interface properties, select IP configurations in Settings. Select ipconfig1 in the IP configurations page. Select Static in Assignment. Select Save.


2 Answers

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

like image 118
Sergey Zyuzin Avatar answered Oct 09 '22 11:10

Sergey Zyuzin


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.

like image 21
Ari Porad Avatar answered Oct 09 '22 13:10

Ari Porad