node.js 打开端口 3000 EC2 Amazon Web 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19337248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening port 3000 EC2 Amazon web services
提问by alias51
I am trying to use nodejs and socket.io to deliver a webapp, which use websocket on port 3000.
我正在尝试使用 nodejs 和 socket.io 来交付一个 webapp,它在端口 3000 上使用 websocket。
I have opened port 3000 on my EC2 instance in my management console by adding the inbound TCP rule to the relevant security group, however I still can't access it via public dns on my browser.
我通过将入站 TCP 规则添加到相关安全组,在我的管理控制台中打开了 EC2 实例上的端口 3000,但是我仍然无法通过浏览器上的公共 dns 访问它。
sudo netstat -tulpn doesn't show it as an open port.
sudo netstat -tulpn 未将其显示为开放端口。
What am I missing? Is there some service I need to restart or a command line I need to push to get it running?
我错过了什么?是否需要重新启动某些服务或需要推送命令行以使其运行?
Thanks
谢谢
采纳答案by slayedbylucifer
sudo netstat -tulpn doesn't show it as an open port.
sudo netstat -tulpn 未将其显示为开放端口。
netstat command will show what all ports that are being listened by "some" process. So in this case as you have mentioned, It seems like you application is not listening on port 3000.
netstat 命令将显示“某个”进程正在侦听的所有端口。因此,在您提到的这种情况下,您的应用程序似乎没有在端口 3000 上侦听。
First, fix your application and ensure that it is listening on port 3000.
首先,修复您的应用程序并确保它正在侦听端口 3000。
Also, netstathas nothing to do with whether a port is opend/closed from firewall perspective. It will tell you whether a given port is in LISTENINGmode by some process.
此外,netstat从防火墙的角度来看,与端口是否打开/关闭无关。它会告诉您某个给定的端口是否处于LISTENING某个进程的模式。
Follow these steps:
按着这些次序:
- Make sure your application is listening on port 3000:
netstat -anp | grep 3000alsotelnet 127.0.0.1 3000 - Then make sure that local firewall is configured to allow incoming access to port 3000
OR disable local firewall to do a quick test (
service iptables stop). for linux, its usuallyiptables - Allow incoming access to port 3000 in your AWS security group.
- 确保您的应用程序正在侦听端口 3000:
netstat -anp | grep 3000也telnet 127.0.0.1 3000 - 然后确保本地防火墙配置为允许传入访问端口 3000 或禁用本地防火墙以进行快速测试 (
service iptables stop)。对于 linux,它通常iptables - 允许传入访问您的 AWS 安全组中的端口 3000。
Please follow above 3 points and let us know if you still face the same issue.
请遵循以上 3 点,如果您仍然面临同样的问题,请告诉我们。
回答by tritium_3
in addition to all the steps above, check if you have ufw (uncomplicated firewall) set up.
除了上述所有步骤外,请检查您是否设置了 ufw(简单防火墙)。
to check if you have ufw running do:
检查你是否有 ufw 运行:
sudo ufw status
if it is running, to allow port 3000 simply do the command
如果它正在运行,要允许端口 3000 只需执行命令
sudo ufw allow 3000
this solved the problem for me. i forgot that i had setup ufw a while back, and recently starting using my aws instance again.
这为我解决了问题。我忘记了我曾经设置过 ufw,最近又开始使用我的 aws 实例。
回答by Artjom Kurapov
Had similar problem, but I was using socketio with SSL
有类似的问题,但我使用的是带有 SSL 的 socketio
var https = require('https').Server({
key: fs.readFileSync(path.join(__dirname + '../) + 'ssl.key', 'utf8'),
cert: fs.readFileSync(path.join(__dirname + '../') + 'ssl.crt', 'utf8')
}, app);
But the keys were wrong, so even though my AWS security was done, iptables clear and nginx providing with client js file, the request kept closing. So in Firefox I got net::ERR_CONNECTION_CLOSED and finally figured out that it might be the SSL failure.
但是密钥是错误的,所以即使我的 AWS 安全已经完成,iptables 清除并且 nginx 提供客户端 js 文件,请求仍然关闭。所以在 Firefox 中我得到了 net::ERR_CONNECTION_CLOSED 并最终发现这可能是 SSL 失败。
回答by Annabel
I guess you made your changes using the AWS Management console. But this just means that Amazon's system will allow message on port 3000 through their own security systems to your server.
我猜您是使用 AWS 管理控制台进行更改的。但这只是意味着亚马逊的系统将允许 3000 端口上的消息通过他们自己的安全系统到达您的服务器。
Your EC2 server (you don't say whether it's Windows or Linux) may have its own firewall system that you have to open port 3000 on. You will have to look at the documentation for your server to what settings you need to change.
您的 EC2 服务器(您不说它是 Windows 还是 Linux)可能有自己的防火墙系统,您必须在其上打开端口 3000。您必须查看服务器的文档以了解需要更改的设置。
I assume you've tried opening a browser on your EC2 instance and you can access the webapp from there.
我假设您已经尝试在 EC2 实例上打开浏览器,并且可以从那里访问 web 应用程序。
Also, thinking laterally, if there are no other web servers running on your EC2 server why not change your node.js webapp to use port 80?
另外,横向思考一下,如果您的 EC2 服务器上没有其他 Web 服务器在运行,为什么不将您的 node.js webapp 更改为使用端口 80?

