gbvc 发表于 2015-9-2 12:45:28

[Linux]Nginx + Node.js + PM2 + MongoDb + (Memcached) Part I

  运行环境:
  在本地的VirtualBox下运行的Ubuntu 14.04 LTS
  0. 查看一下Server的IP地址
ifconfig
  我的Server IP是192.168.0.108
  1. 安装Nginx
  首先更新 APT 包管理 ,然后安装Nginx

sudo apt-get update
sudo apt-get install nginx  然后重启一下本地的 Nginx的服务


service nginx restart  然后在浏览器 键入192.168.0.108
  应该可以看到如下的Nginx欢迎页面

  2.安装Node.js
  在Ubuntu 14.04的版本中可以使用 APT直接安装Node.js


sudo apt-get install nodejs  检查一下Nodejs 的版本


nodejs -v  
  
  
  3. 创建简单的 Node.js App
  先在/var/www下创建一个 App的文件夹 “helloApp” ,然后创建命名为app.js的文件


mkdir /var/www
mkdir /var/www/helloApp
cd /var/www/helloApp
vi app.js  下面是简单的代码,就是 http://www.nodejs.org 上的那个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/');  然后用nodejs 执行


nodejs app.js  如果用Putty的话,可以新开一个terminal用crul看看是执行正常
页: [1]
查看完整版本: [Linux]Nginx + Node.js + PM2 + MongoDb + (Memcached) Part I