Setting up production environment on EC2 Ubuntu instance


sudo apt-get update 
sudo apt-get upgrade -y


sudo apt-get install build-essential libssl-dev -y


The easiest and fastest way is Installing node via package manager

But in practice, to avoid some drawbacks with sudo npm install and benefit from easy switching between node versions installing nodel via NVM seens nuch better.

curl | bash
source ~/.bashrc

Then install stable node version, which is 0.12.0 at the time of writing. Also set it as default to be used with new shell and after server reboot.

nvm install stable
nvm alias default stable


Installing MongoDB on Ubuntu

# Import the public key used by the package management system
sudo apt-key adv --keyserver hkp:// --recv 7F0CEB10

# Create a list file for MongoDB
echo "deb "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

# Reload local package database
sudo apt-get update

# Install MongoDB
sudo apt-get install -y mongodb-org

Now you can manage mongod service with following commands

sudo service mongod start
sudo service mongod stop
sudo service mongod status


sudo apt-get install nginx -y

Now you can manage nginx service with following commands

sudo service nginx start
sudo service nginx stop
sudo service nginx status

NginX should boot up automaticaly, you verify that with sudo service nginx status but also after you navigate to public dns or public ip of your ec2 instance you should see:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to
Commercial support is available at

Thank you for using nginx.

Make sure NginX starts after server reboot

sudo update-rc.d nginx defaults


Copy and paste below installation instruction

sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get install git -y

Check version with

git --version



Add two A type record sets with values as in example shown below where x.x.x.x stands for your instance IP address or better elastic IP address associated with the instance.

  • first with blank name:
type: A 
value: x.x.x.x
TTL: 300
  • second with 'www' as name:
type: A 
value: x.x.x.x
TTL: 300


Check out "Installing NginX on AWS EC2 for NodeJS" for configuration and examples. To get nginx configuration wget nginx.conf gist.
sudo wget -O /etc/nginx/nginx.conf
Alternatively manualy review, edit `/etc/nginx/nginx.conf` and paste [NginX configuration for NodeJS web app on AWS EC2]( #### Log rotation with log rotate To avoid heavy logs edit `sudo nano /etc/logrotate.d/nginx`. - Change 'weekly' to 'daily' to rotate logs daily - Update 'rotate' for number of archives ### MongoDB Following official guide: [MongoDB on Linux]( #### Disable transparent huge pages Jira [ticket]( Update `/etc/rc.local` to disable `transparen_hugepages`
sudo wget -O /etc/rc.local
Or alternatively copy and paste below code manualy.
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
if [ "$mongo_restart" = 1 ]; then
   service mongod restart
#### Monitoring Monitoring alternatives: - [MMS]( - Mongo Monitoring System - Munin - requires [munin plugin]( ### Node #### Packages



Published by IndieForger