我有一个在Ubuntu服务器上运行的node.js应用程序。 我能够-X SSH进来,并检查它是用localhost:4000上的firefox正常运行。
然后,我从Azure门户添加一个新的入站安全规则。
该网站仍然不能从服务器外部访问。 我从桌面上运行以下内容:
telnet 104.99.99.99 4000
我连接超时。
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
安全规则:
我的脑海里有三样东西:
netstat -anep | grep -w 4000 netstat -anep | grep -w 4000 ,并确保它正在使用您使用的networking接口(不pipe是eth0还是其他)的0.0.0.0或IP上进行监听。 如果它正在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地址或任何公用IP地址访问它。