2015-11-26 128 views
0

我有一个Amazon EC2服务器,我已经配置了节点js服务器,但它不能从外部通过公共dns访问,但可以通过同一实例(本地主机)访问。任何帮助都感激不尽。Node.js不能从外部IP访问

服务器代码:

var my_http = require("http"); 
my_http.createServer(function(request,response){ 
    console.log("Request Recieved : "+request.url); 
    response.writeHeader(200, {"Content-Type": "text/plain"}); 
    response.end("Server is UP \n"); 
}).listen(3000, "0.0.0.0"); 
console.log("Server is Running on Port 3000"); 

netstat的输出

netstat -tupln | grep :3000 
tcp 0 0 0.0.0.0:3000  0.0.0.0:* LISTEN 11706/node 

卷曲输出

curl http://127.0.0.1:3000    =>  Server is UP 
curl http://localhost:3000    =>  Server is UP 
curl http://{PRIVATE_IP}:3000    =>  Server is UP 
curl http://{PUBLIC_DNS}:3000    =>  curl: (52) Empty reply from server 
+2

您是否在安全组中打开了端口3000? –

+0

是,端口80,22,3000,3001是开放的 – Shashi

回答

2

它确实左声道L这是一个安全组问题。

在您的EC2控制面板中,找到您的实例并一直滚动到右侧。有一个安全组列,如果您没有更改默认名称,您的安全组将被称为“launch-wizard-1”。

单击它,并打开一个过滤的安全组列表(可能只有一个列表中的条目)。

右键单击它并选择编辑入站规则。

添加规则说:

Type: HTTP 
Protocol: TCP 
Port Range: 3000 
Source: Anywwhere 

保存,它应该工作。