gpt4 book ai didi

node.js - 无法从外部访问 NodeJS 服务器

转载 作者:搜寻专家 更新时间:2023-10-31 22:26:50 25 4
gpt4 key购买 nike

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

curl http://127.0.0.1:8080

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

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/');

有什么想法吗?

最佳答案

我认为您应该尝试不指定 IP。

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

关于node.js - 无法从外部访问 NodeJS 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8017674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com