无法连接到托管在亚马逊EC2节点的Web服务器 [英] Can't connect to Node web-server hosted on Amazon EC2
问题描述
我运行在Amazon EC2的一个节点的应用程序。该应用程序包括一个简单的Web服务器用来服务于索引页,但它不工作。
I'm running a node app on an Amazon EC2. The app includes a simple web server intended to serve the index page, but it doesn't work.
下面是服务器code:
Here's the server code:
var http = require('http'),
fs = require('fs'),
io = require('socket.io'),
index;
fs.readFile('client.html', function(err, data){
if (err){
throw err;
}
index = data;
});
var server = http.createServer(function(request, response){
response.writeHeader(200,{"Content-Type": "text/html"});
response.write(index);
response.end();
}).listen(1223);
在EC2分配的公网IP地址 54.187.31.42
。我运行应用程序,打开浏览器,连接到 54.187.31.42:1223
预计送达的网页和什么也得不到。
The EC2 is assigned the public IP address 54.187.31.42
. I run the app, open my browser, connect to 54.187.31.42:1223
expecting to be served a web page and get nothing.
-
什么是错我的服务器code?
What is wrong with my server code?
我用这个答案检查应用程序运行在EC2的IP,奇怪获得 172.31.3.67
- 为什么是返回地址从一个亚马逊分配给本机有什么不同?
I used the snippet found in this answer to check the IP of the EC2 running the app, and oddly get 172.31.3.67
- why is the returned address different from the one assigned to the machine by Amazon?
因此,尝试连接到 172.31.3.67:1223
也失败了。
Consequently, trying to connect to 172.31.3.67:1223
also fails.
直接从亚马逊开发的控制,如果这能帮助确认是不是的服务器的IP是错了或什么的问题。
Straight from the Amazon dev controls, if that helps confirm it isn't an issue of the server IP being wrong or something.
推荐答案
在code看起来不错,尝试与您在AWS控制台中看到的公共IP /公共DNS连接。
The code looks fine, try connecting with the public IP/public DNS that you see in the AWS console.
请尝试以下方法,你的应用程序将工作:
Try the following and your application would work:
- 打开的端口(在你的案件1223)在您的实例的安全组。
- 停止防火墙的机器上(如iptables的),现在使用公网IP或公共DNS访问您的服务器。
如果您现在可以acceess你的机器,这意味着什么,在iptables的过滤了您的流量。您可以修改相应的iptables规则。
If you can now acceess your machine that means something in the iptables is filtering your traffic. You can modify the iptables rules accordingly.
这篇关于无法连接到托管在亚马逊EC2节点的Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!