Install Nginx and Passenger to Deploy Rails App

1. Install Phusion Passenger:

gem install passenger


2. Install Nginx:

# Install Nginx

rvmsudo passenger-install-nginx-module


# Install Nodejs if you do not yet have it

sudo apt-get install nodejs


# Download nginx startup script

wget -O


# Move the script to the init.d directory & make executable

sudo mv /etc/init.d/nginx

sudo chmod +x /etc/init.d/nginx


# Add nginx to the system startup

sudo /usr/sbin/update-rc.d -f nginx defaults


# Start nginx

sudo service nginx start


3. Connect Nginx to Your Rails App

# The Nginx configuration file (/opt/nginx/conf/nginx.conf)

sudo nano /opt/nginx/conf/nginx.conf


# Add configuration follow the syntax:

server {

  listen 80;

  server_name localhost:3000;

  # Tell Nginx and Passenger where your app's 'public' directory is

  root /home/ubuntu/luannt/rails_app/public/;   

  # Turn on Passenger

  passenger_enabled on;

  passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.1.2@blog/wrappers/ruby;


Remember restart Nginx when you are done

sudo service nginx restart