【发布时间】:2017-03-31 12:56:03
【问题描述】:
我启动了运行 ubuntu 12.04 的亚马逊 ec2 实例
然后我按照说明从这里 http://howtonode.org/how-to-install-nodejs 安装 node.js
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install
然后我使用示例代码制作hello.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
然后我跑了hello.js
/var/www$ node hello.js
Server running at http://127.0.0.1:8124/
但是,当我尝试使用 http://ec2-***.compute-1.amazonaws.com:8124/ 从 url 访问它时,我的浏览器会出现错误页面。
关于如何让它显示在浏览器中的任何建议?
编辑 改了上面这行代码后还是遇到这个问题
}).listen(8124, "127.0.0.1");
到这里
}).listen(8124);
【问题讨论】:
标签: javascript linux node.js ubuntu amazon-ec2