I have a node.js app running on an Ubuntu server. I was able to -X SSH
in and check that it was running properly with firefox on localhost:4000.
I then add a new inbound security rule from the Azure portal.
The site still isn't accessible from outside the server. I run the following from my desktop:
telnet 104.99.99.99 4000
And I get connection timed out.
Results from sudo iptables -L
:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootpc
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Security rule:
3 вещи приходят мне в голову:
netstat -anep | grep -w 4000
и убедитесь, что оно прослушивает либо 0.0.0.0, либо IP сетевого интерфейса, который вы используете (будь то eth0 или что-то еще). Если он прослушивает 127.0.0.1, то он не будет доступен из внешнего мираiptables -L
. Чтобы отобразить их все, используйте: iptables -vL -t filter
, iptables -vL -t nat
, iptables -vL -t mangle
, iptables -vL -t raw
, iptables -vL -t security
Вы упомянули, что NodeJS прослушивает localhost: 4000.
Это означает, что он доступен только изнутри вашего собственного сервера. Служба NodeJS должна прослушивать 0.0.0.0:4000 (для любого интерфейса) или your.private.ip.address: 4000 для определенного интерфейса, например:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(4000, "0.0.0.0");
console.log('Server running at http://0.0.0.0:4000/');
Приведенный выше фрагмент запускает сервер на 0.0.0.0: 4000, так что вы можете получить к нему доступ извне с 104.99.99.99:4000 или любого другого публичного IP-адреса, который у вас есть.