All posts by Ramesh Jha

Adding SSL to a Rails Application

Adding SSL to a new or existing Rails application isn’t really that difficult. If the website exists for a while and you want to move to https, then you must properly redirect (301) visitors to the new url. If it’s a new website, then it’s probably a good idea to use SSL from the start. (it’s must if you collect any kind of sensitive data from the users)

Assumptions : It’s a Rails 4 app, running with nginx, passenger and Ubuntu 14.04 Server. (preferably on VPS, or somehow you should be able to update nginx configs and so). For SSL certificate, I would recommend Comodo PositiveSSL Certificate from NameCheap @ $9 a year, unless you’ve a good reason to spend more on that.

SSL Setup

First, generate a key and then CSR for buying a SSL certificate. Enter the required info as required. Watch out for Common Name / FQDN field, it must match with the domain (in this case :

openssl genrsa -out 2048
openssl req -new -key -out

Then copy the content of above csr file to your clipboard (use xclip, a command line utility) and paste that into SSL order form.

xclip -sel clip < path_to_your_csr_directory/

Next, you’ll receive a confirmation email. After confirming that, they will email you the certificate. (usually within few hours)

Once you receive the ssl certificate (usually in *.zip format), extract the zip file (containing certificates) and concatenate them in right order to get a single certificate file.

cat www_example_com.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt > ssl-bundle.crt

Now, you need to upload these two files – ssl-bundle.crt and (the private key, generated earlier) to the server. (use scp. e.g scp target_file user@server_ip:file_name)

Preparing Rails for SSL

Enable SSL in production mode, by updating the config/environments/production.rb file.

config.force_ssl = true

And you also need to make sure all the external resources (e.g fonts, images, css, js etc) are loaded securely over https only.

Nginx setup

Login to VPS/Server and create/update your nginx config for ssl.

sudo nano /etc/nginx/sites-available/

A sample nginx config for Rails Application.

Now, enable that nginx config and reload the server.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo service nginx reload

Monitor your bandwidth usage with vnstat [Ubuntu/Linux]

vnstat is a simple command line utility for monitoring bandwidth usage in Ubuntu or any other Linux based distributions and BSD. It’s a very handy tool for keeping an eye on overall bandwidth usage on your system, especially if you’re accessing web over mobile network or you’re using ISP that reduces speed after a certain limit e.g 50 GB (FUP).



  • very lightweight and efficient (low cpu usage regardless of traffic)
  • simple and easy to use (no configuration required)
  • it can monitor multiple interfaces simultaneously
  • multiple output options (daily, monthly etc)

Installing vnstat in Ubuntu/Linux

It’s already there in official package repository, all you need to do is open a terminal and type :

sudo apt-get install vnstat

As you install vnstat, it will start monitoring your internet traffic (default interface : eth0). Simply type vnstat to get an overview of actual bandwidth usage and the estimated usage for next day or month. It will also display the interface(s) it’s monitoring.


For all available options, type :

vnstat --help

Few commands you should know

  • vnstat -d : for daily stats
  • vnstat -w : for weekly stats
  • vnstat -m : for monthly stats
  • vnstat -l : for analyzing live traffic
  • vnstat -t : shows usage statistics for top 10 days

Deploying static websites to VPS using git

git is a distributed open source version control system. If you’re not already familiar with git then read some free tutorials listed here and come back after you have some basic understanding to follow through the tutorial. Whether it’s a static website or a fun project, it’s usually a good idea to use a version control system such as git. Additionally, git can also help you in deployment and make your development workflow much easier and simpler.

git deployment

Step #1. Server Setup

If you’ve not already selected a VPS then get one there on Digital Ocean or Linode. Make sure you select Ubuntu (preferably : 14.04 LTS) for the server OS. Otherwise, you may need to adjust few commands depending on the Linux distribution you’re using.

Step #2. Configure git on the server

SSH into the remote server and configure git for deployment.

ssh example_user@IP_ADDRESS
mkdir example.git
cd example.git
git init --bare

Next, create a git hook – a shell script that will be executed on git push (to update code on server).

nano ~/example.git/hooks/post-receive

Here is a sample post-receive script you can use : (use Ctrl+X to save and exit)

And make it executable.

chmod +x ~/example.git/hooks/post-receive

Step #3. Install and configure git on dev machine

First, install git, move into your project directory and commit it under git.

sudo apt-get -y install git-core
git init
git add .
git commit -am "MVP is ready for the wild"

Add remote repository for deployment server.

git remote add production ssh://example_user@IP_ADDRESS/~/example.git

And now, you’re ready to deploy. Just type (to push recent changes to live server) :

git push production master

Step #4. Configure nginx

ssh into the server and create a nginx config for the domain (

sudo nano /etc/nginx/sites-available/example.conf

Here is a sample config you could use :

sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/
sudo service nginx reload

Now, update the DNS settings at the registrar and create two records – one for naked domain (e.g and other for www-version of the website (e.g – both pointing to the server IP. And, wait for the DNS to be propagated (few minutes).

Calculate your income tax liability using this free online tool [India]

If you’re paying taxes in AY 2015-16 (FY 2014-15) you may want to get a rough estimate before you go to a tax consultant (or do it yourself). For that purpose, you may want to check out this income tax calculator I launched few days ago.

income tax liability

It’s a simple web based tool that helps you get an overview of your total income tax liability (or refund) for the current assessment year. The process is straightforward and simple with step-by-step guide for each sections. (especially for beginners)

income details


First, select your age and financial year (2014-15 is selected by default) and enter your income details in 2nd step. Make sure you add all income sources correctly and also the amount of tax paid in advance (TDS, TCS etc).


Then, you can enter the amounts for eligible deductions before you get to the final report on your tax liability/refund.  The deduction page helps you in the process by offering simple and easy to understand interpretation for various sections including section 80C, 80D, 80G, 80E and so. Make sure you read all the details before moving to the next.

Visit the Website :

Update! Also check out this one if you invest in mutual funds through SIP (Systematic Investment Plan) and for calculating internal rate of return for an investment.

Fish – A user friendly command line shell for Ubuntu/Linux

Fish is a friendly command line shell for Ubuntu/Linux, Mac or any other operating system from the *nix family. If you use bash (the default shell in Ubuntu) often, then you may want to give it a try. It has lots of smart features you may find productive.

fish shell


  • Autosuggestions – It suggests commands when you type, based on history and it’ll often save you some time with the commands you type more often.
  • Scripting – Similar to bash but the syntax is much simple, clean and consistent.
  • term256 – it supports 256 colors.
  • Sane defaults – Most of the features will work just fine without any additional configurations.

Installing Fish in Ubuntu

Fish is already there in official package repository (tested on Ubuntu 14.04 LTS). So, you can install it right away

sudo apt-get update
sudo apt-get install fish

If it’s not available in repository or you’re using other Linux distribution ? Check out official page to download a tarball for your distribution.

To start fish, simply type fish on your terminal and you’ll jump into the fish shell. Type help and it will open the documentation tab (hosted locally) in your default browser. Also read official tutorials to learn more about the features of Fish Shell.