无法从外部访问NodeJS服务器 [英] NodeJS server not accessible from outside

查看:206
本文介绍了无法从外部访问NodeJS服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rackspace中部署了一个nodejs服务器,可以在内部访问它,例如使用:

I deployed a nodejs server in Rackspace and can be accessed internally, like using:

curl http://127.0.0.1:8080

但是,即使我这样做,也无法从外部(互联网)访问它:

However, it can't be accessed from the outside (the internet) even if I do this:

iptables -A OUTPUT -p tcp  --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp  --dport 8080 -j ACCEPT

这是我的代码的样子:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Simple server\n');
}).listen(8080, "0.0.0.0");
console.log('Server running at http://0.0.0.0:8080/');

有什么想法吗?

推荐答案

我很确定您必须使用

iptables -A OUTPUT -p tcp  --sport 8080 -j ACCEPT

表示传出规则(不是dport).除此之外,也许还有更早的规则可以阻止流量?尝试iptables -L.

for the outgoing rule (not dport). Apart from that, maybe there's an earlier rule that blocks the traffic? Try iptables -L.

这篇关于无法从外部访问NodeJS服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆