Setting up Unicorn with Nginx on Ruby on Rails


In this blog post, I am going to tell you, How to configure Unicorn web sever on top of Nginx. I Assume that you already installed Ruby and Ruby on Rails on your production OS(operating system) and a sample application working fine.!! If not, follow my previous blog post Setup Ruby On Rails on Ubuntu.

Nginx and Unicorn

To get you started, Let’s install Nginx first by using apt-get package manager.

$ sudo apt-get install nginx

Sometime you get ERROR because your machine packages are not upto date. Run apt-get update to downloads the package lists from the repositories and “updates” them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.

$ sudo apt-get update

Once your nignx will install, you command window will prompt:

Setting up nginx-full (1.2.1-2.2ubuntu0.1) ...
Setting up nginx (1.2.1-2.2ubuntu0.1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for sgml-base ...
Updating the super catalog...

At this point switch to /etc/nginx/ and /etc/nginx/sites-available configuration directory and have a look to nginx.conf and default respective configuration file. It’s self explanatory under commented in-lines. If still you need more details. I will recommend you to check wiki.nginx for more info.

While the server configuration it’s always better to create separate user(which we have more control over than nobody) for security reasons and increased control by using below command:

$ sudo useradd -s /sbin/nologin -r nginx
$ sudo usermod -a -G web nginx

Starting/stopping/restarting Nginx is pretty straight forward.

$ sudo service nginx start/restart/stop

Now let’s install Unicorn, Unicorn is distributed as ruby gem So you can install vi ruby gem.

$ gem install unicorn

Once Unicorn installed successfully. We need to create two configuration file.

1.Replace /etc/nginx/sites-available/ default file with below code:

upstream shop {
  server unix:/tmp/unicorn.shop.sock fail_timeout=0;
}

server {
   listen 80;# default deferred;
   server_name localhost;
   root /var/www/shop/public;
   try_files $uri/index.html $uri @shop;

location @shop {
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header Host $http_host;
   proxy_redirect off;
   proxy_pass http://shop;
}

error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
   keepalive_timeout 10;
}

2. Create a unicorn.config file in your Rails application configuration file with below code:

working_directory "/var/www/shop"
pid "/var/www/shop/tmp/pids/unicorn.pid"
stderr_path "/var/www/shop/log/unicorn.log"
stdout_path "/var/www/shop/log/unicorn.log"

listen “/tmp/unicorn.shop.sock”
worker_processes 2
timeout 30

You have to tweak a few things to set the right paths in above configuration. Change “/var/www/shop” with your rails application directory.

In my case my Rails application is in /var/www/ with shop name.

Before start your rails application, make sure to include unicorn gem in your Gemfile and run bundle to install all dependencies.

That’s all.

Setup Ruby On Rails on Ubuntu


Installation of Ruby on Rails for Production server is pretty straight forward. Below are the relevant steps.

1.INSTALL THE NEEDED LIBRARIES

sudo apt-get install zlib1g zlib1g-dev build-essential openssl libssl-dev libmysqlclient18 libmysqlclient-dev libyaml-dev

2.DOWNLOAD AND INSTALL RUBY 1.9.3

sudo apt-get update
 sudo apt-get install ruby1.9.3

Note you can install latest Ruby too.

3.INSTALL RAILS

 sudo apt-get install ruby-dev
 sudo apt-get install build-essential g++
 sudo gem install railsconfigure rails application with nginx and unicorn

4.INSTALL SQLITE ADAPTER

 sudo apt-get install libsqlite3-dev

If you passed all above steps without any ERROR, Now it’s time to create a rails demo application OR SCP existing one and test it out.

Below is the steps to create new rails application

 rails new demo
 cd demo
 uncomment therubyracer gem in Gemfile
 sudo apt-get install build-essential g++
 bundle install
 rails g scaffold order name:string
 rake db:create
 rake db:migrate

Open config/routes file and uncomment root ‘welcome/index’ and replaced with ‘orders/index’

$rm -rf public/index

That’s all, Now run your Rails application.

Netbeans add ruby platform


Install RVM and Ruby version what ever you want .

Once you done with ruby installation,
From terminal type below command..

$rvm use 1.9.1
$cd /home/alan/programs/netbeans_6_8/bin ***or wherever your netbeans is installed
$./netbeans

I hope, it will help.
For details visit http://www.skorks.com/2010/01/using-multiple-rubies-seamlessly-on-the-one-machine-with-rvm/comment-page-1/#comment-3422

Cheers

 

error: AttributeError(“‘module’ object has no attribute ‘binary'”, )


I was facing same issues, After couple of hours google search i found this solutions.

https://github.com/JeffAMcGee/Fang-of-Mongo/commit/202fd95b5a6558fc60d85bd94ec6a9c6a3c14a2e#diff-0

We need to do some update in /home/maisa/workspace/Fang-of-Mongo/fangofmongo/fom

In your case may it differ, Here /home/maisa/workspace is my working directory where, I cloned Fang-of-Mongo.

Go to Fang-of-Mongo/fangofmongo/fom folder and open view.py file and these changes.

https://github.com/JeffAMcGee/Fang-of-Mongo/commit/202fd95b5a6558fc60d85bd94ec6a9c6a3c14a2e#diff-0

That’s working fine for me. Enjoy..!!!!!!!!!!!!!!!1

Install NetBeans IDE on Ubuntu 11.10


1. Make sure, You Added PPA repository to my Ubuntu.

sudo add-apt-repository ppa:ferramroberto/java

2.After adding PPA, update your system apt:

sudo apt-get update

3.Install the Java Development Kit:

sudo apt-get install sun-java6-jdk

If you have problem with java installation , take a look to install-java-and-java-browser-plugin-ubantu-11-10 .

4. Go to the folder where you want to download NetBeans and download by typing:

wget http://download.netbeans.org/netbeans/7.0.1/final/bundles/netbeans-7.0.1-ml-php-linux.sh

5.Give yourself permissions to execute the install script you have just downloaded:

chmod u+x netbeans-7.0.1-ml-php-linux.sh

6. Now run netbeans:

./netbeans-7.0.1-ml-php-linux.sh

Just do next as window, and click desktop icon to start NetBeans:

That’s it. Enjoy……………