Skip to content

Instantly share code, notes, and snippets.

@crystal520
Forked from pjnovas/InstallationStack.md
Last active August 31, 2016 19:16
Show Gist options
  • Save crystal520/0dc0e394d99d09497930 to your computer and use it in GitHub Desktop.
Save crystal520/0dc0e394d99d09497930 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
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

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

(should automatically started)

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
sudo npm install bower -g
sudo npm install pm2 -g
npm install grunt --save-dev
sudo apt-get install ruby-full
sudo gem install sass

Now copy the template config.json and configure

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

sudo npm install pm2 -g sudo pm2 start grunt sudo pm2 logs --lines 10

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