Deploying ruby on rails application with Nginx + Passenger in few simple steps

Nginx is web server like Apache. Passenger is application server like Puma,Thin, Mongrel, Webrick.
Today We are going see different steps of installation of passenger module in Nginx because Nginx can't dynamically load modules like Apache does.

If we want to load passenger module in Nginx we have to reinstall Nginx, which is quite frustrating.

Though Passenger has provided utility to install it named as


This utility will install nginx for us and also add passenger module with it.

To do that we need to install passenger gem :
gem install passenger

Now, execute command 
rvmsudo passenger-install-nginx-module

This will install nginx with passenger module for us.

In the process of installation, it will ask for location where you want to put your nginx
by default it is /opt/nginx but we choose here /etc/nginx.

Lets create new rails application to deploy :
rails new sample_nginx_app

Configure nginx :
sudo vim /etc/nginx/config/nginx.conf

Here is my nginx.conf looks like. 
Note : You can edit config file and add more attributes you want, but for now this are required to run our app.

Now start server by :
sudo service nginx start

You will get error service not found.

As passenger has installed nginx server, it will not create service to run nginx server. 
So we need to create one for it
Script Credit goes to :

Save above content in :

execute following command : 
sudo mv /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

Now try to  run server again with :

sudo service nginx start

Open in brower and you should see Rails home page.

Note : must be in /etc/hosts file. 

You can add it by :
$sudo vim /etc/hosts

add this:

and save it.

when you execute : 
$cat /etc/hosts

It should look like this localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

That's it!!! Your app is configured behind web server Nginx and application server Passenger. However there is also another way to make things done but I find this way more handy.

Hope you find this article helpful.