Skip to content

Instantly share code, notes, and snippets.

@eneim
Forked from pjnovas/InstallationStack.md
Created June 27, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eneim/30a9598cc049ae0df32f4f220e81b707 to your computer and use it in GitHub Desktop.
Save eneim/30a9598cc049ae0df32f4f220e81b707 to your computer and use it in GitHub Desktop.
Complete Install on Ubuntu Server of Nodejs + MongoDB + NGINX

##Ubuntu Server

NodeJS

sudo apt-get install g++ curl libssl-dev apache2-utils git-core make
cd /usr/local/src
wget http://nodejs.org/dist/v0.10.28/node-v0.10.28.tar.gz
tar -xvzf node-v0.10.28.tar.gz
cd node-v0.10.28
./configure
make
sudo make install 

Now check for NodeJS and NPM versions

node --version
npm --version

MongoDB

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-org

Then Start Mondgo DB Service

sudo /etc/init.d/mongod start

Check if it has executed correctly

vim /var/log/mongodb/mongod.log

it could take a while .. mongo preallocates 3.0gb so wait for message like:

2014-05-24T03:12:17.599+0000 [initandlisten] waiting for connections on port 27017

To Run a client of mongodb and see current DBs

$ mongo
> show dbs

More Info at MongoDB


Install the NodeJS process pulling from git

mkdir -p /var/www/
cd /var/www/
git clone https://github.com/user/project-name.git
cd project-name/
npm install --production

Now copy the template config.json and configure

cp config.env.json.sample config.prod.json
vim config.prod.json

Install Forever Globally to run nodejs

npm install -g forever

Run NodeJS Process at production environment on port 5000

NODE_ENV=production PORT=5000 forever start ./bin/www

Check if process is runing and log

forever list
forever logs 0

NGINX

sudo apt-get install nginx
sudo service nginx start

Configure the NodeJS Process

vim /etc/nginx/sites-enabled/default

Add the following lines after location / {

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:5000/;
proxy_redirect off;

Then restart NGINX:

sudo service nginx restart

Now go to your browser and put the http://SERVER-IP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment