Time for flying rainbow horses. Start by installing the Unicorn gem:
gem install unicorn
You should now have Unicorn installed: unicorn (for non-Rails rack applications) and unicorn_rails (for Rails applications version >= 1.2) should be in your path.
Time to take it for a spin! (You may wish to re-login with su - USERNAME if you haven’t already, this ensures your permission tokens are set, otherwise you will not have write permission to /var/www)
rails new unicorn
There we go, we now have our Unicorn Rails test app in /var/www! Let’s fetch some Unicorn config and start the madness. We’re going for the unicorn.conf example that comes with the Unicorn source:
curl -o config/unicorn.rb
You might want to tweak a few things:
APP_PATH = "/var/www/unicorn" working_directory APP_PATH
stderr_path APP_PATH + "/log/unicorn.stderr.log"
stdout_path APP_PATH + "/log/unicorn.stderr.log"
pid APP_PATH + "/tmp/pid/unicorn.pid"
Our Unicorn is ready! Rainbow magic
Start the Nginx deamon, how this is done depends on your OS. And then start Unicorn:
unicorn_rails -c /var/www/unicorn/config/unicorn.rb -D
-D deamonizes it. -c should be pretty obvious; it specifies the configuration. In production you will probably want to pass -E production as well to run the app in the production environment.
That’s it! Visiting localhost should take you to the Rails default page.