打开端口3000 EC2亚马逊网络服务

时间:2023-01-26 13:05:27

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.

我已经在我的管理控制台中的EC2实例上打开了端口3000,将入站TCP规则添加到相关安全组,但是我仍然无法通过浏览器上的公共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

谢谢

4 个解决方案

#1


9  

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, netstat has nothing to do with whether a port is opend/closed from firewall perspective. It will tell you whether a given port is in LISTENING mode by some process.

此外,netstat与端口是否从防火墙角度打开/关闭无关。它会通过某个进程告诉您某个端口是否处于LISTENING模式。

Follow these steps:

按着这些次序:

  1. Make sure your application is listening on port 3000: netstat -anp | grep 3000 also telnet 127.0.0.1 3000
  2. 确保您的应用程序正在侦听端口3000:netstat -anp | grep 3000也telnet 127.0.0.1 3000
  3. 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 usually iptables
  4. 然后确保本地防火墙配置为允许对端口3000的传入访问或禁用本地防火墙进行快速测试(服务iptables停止)。对于linux,它通常是iptables
  5. Allow incoming access to port 3000 in your AWS security group.
  6. 允许对AWS安全组中的端口3000进行传入访问。

Please follow above 3 points and let us know if you still face the same issue.

如果您仍然面临同样的问题,请按照以上3点告诉我们。

#2


1  

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实例上打开浏览器,您可以从那里访问webapp。

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?

#3


1  

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 clear和nginx提供了客户端js文件,请求仍然关闭。所以在Firefox中我得到了net :: ERR_CONNECTION_CLOSED,最后发现它可能是SSL失败。

#4


0  

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:

检查你是否有自己的运行:

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.

这解决了我的问题。我忘记了我已经设置了一段时间了,最​​近又开始使用我的aws实例了。

#1


9  

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, netstat has nothing to do with whether a port is opend/closed from firewall perspective. It will tell you whether a given port is in LISTENING mode by some process.

此外,netstat与端口是否从防火墙角度打开/关闭无关。它会通过某个进程告诉您某个端口是否处于LISTENING模式。

Follow these steps:

按着这些次序:

  1. Make sure your application is listening on port 3000: netstat -anp | grep 3000 also telnet 127.0.0.1 3000
  2. 确保您的应用程序正在侦听端口3000:netstat -anp | grep 3000也telnet 127.0.0.1 3000
  3. 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 usually iptables
  4. 然后确保本地防火墙配置为允许对端口3000的传入访问或禁用本地防火墙进行快速测试(服务iptables停止)。对于linux,它通常是iptables
  5. Allow incoming access to port 3000 in your AWS security group.
  6. 允许对AWS安全组中的端口3000进行传入访问。

Please follow above 3 points and let us know if you still face the same issue.

如果您仍然面临同样的问题,请按照以上3点告诉我们。

#2


1  

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实例上打开浏览器,您可以从那里访问webapp。

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?

#3


1  

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 clear和nginx提供了客户端js文件,请求仍然关闭。所以在Firefox中我得到了net :: ERR_CONNECTION_CLOSED,最后发现它可能是SSL失败。

#4


0  

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:

检查你是否有自己的运行:

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.

这解决了我的问题。我忘记了我已经设置了一段时间了,最​​近又开始使用我的aws实例了。