简体   繁体   English

Node.js在Amazon EC2 Ubuntu 14.04服务器上不起作用?

[英]Node.js doesn't work on Amazon EC2 Ubuntu 14.04 server?

I setup a ubuntu14.04 server on Amazon EC2 recently, when I install the nodejs using shell: 我最近在使用shell安装nodejs时在Amazon EC2上设置了ubuntu14.04服务器:

curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs

It says nodejs is already the newest version. 它说nodejs已经是最新版本。 In order to check successful Node installation ,I write this in a test.js file 为了检查Node是否成功安装,我将其写入test.js文件

var sys = require("sys");  
sys.puts("Hello World");

when I try 当我尝试

node test.js

I got nothing in the shell.strange..someohelp? 我在shell.strange..someohelp中什么都没有?

I follow the offical demo 我按照官方演示

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

save it as server.js try to run it with node server.js doesn't work... 将其保存为server.js尝试与节点server.js一起运行不起作用...

But it works well in my local ubuntu server machine. 但这在我的本地ubuntu服务器计算机上运行良好。 So I guess it's may be an Amazon's problem? 所以我想这可能是亚马逊的问题?

I see this thread: 我看到这个线程:

Can't connect to Node web-server hosted on Amazon EC2 无法连接到Amazon EC2上托管的Node Web服务器

and it's not work on my problem too.After I allow all traffic from everywhere on all ports.Still get the same problem. 并且在我的问题上也不起作用。在我允许所有端口上的所有位置的所有流量通过后,仍然遇到相同的问题。

BTW,I'm using PUTTY to connect to the server. 顺便说一句,我正在使用PUTTY连接到服务器。

It's right that ubuntu 14.04 have a diffent version of nodejs.So I download the .tar.gz file from the offical website the unpack it , and run 没错,ubuntu 14.04的nodejs版本不同,所以我从官方网站下载了.tar.gz文件,将其解压缩并运行

./configure && make && sudo make install

Then it works for me.... 那对我有用...

node != nodejs. 节点!= nodejs。 Try running: nodejs test.js 尝试运行:nodejs test.js

The problem is that some versions of Ubuntu including 14.04 need to have a different package installed for nodejs. 问题是某些版本的Ubuntu(包括14.04)需要为nodejs安装其他软件包。 There is a conflict with the node process and you're not actually run node but some other application. 节点进程存在冲突,您实际上不是在运行节点,而是在运行其他一些应用程序。

To resolve the problem install nodejs using sudo apt get install nodejs-legacy . 要解决此问题,请使用sudo apt get install nodejs-legacy安装nodejs以sudo apt get install nodejs-legacy After doing that you should see a version returned if you run node --version . 这样做之后,如果运行node --version ,应该会看到返回的node --version

Try: 尝试:

 sudo node test.js 

It worked for me 对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM