Using with Rails

Add thin to your Gemfile

gem 'thin'

Start Thin

bundle exec thin start

Using with anything, ANYTHING!

But Thin can also load Rack config file so you can use it with any framework that supports Rack. Even your own that is, like, soooo much better then Rails, rly!

fart.ru
app = proc do |env|
  [
    200,          # Status code
    {             # Response headers
      'Content-Type' => 'text/html',
      'Content-Length' => '2',
    },
    ['hi']        # Response body
  ]
end

# You can install Rack middlewares
# to do some crazy stuff like logging,
# filtering, auth or build your own.
use Rack::CommonLogger

run app
thin start -R fart.ru

See Rack doc for more.


Deploying

Deploying a cluster of Thins is super easy. Just specify the number of servers you want to launch.

thin start --servers 3

You can also install Thin as a runlevel script (under /etc/init.d/thin) that will start all your servers after boot.

sudo thin install

and setup a config file for each app you want to start:

thin config -C /etc/thin/myapp.yml -c /var/...

Run thin -h to get all options.

Behind Nginx

Check out this sample Nginx config file to proxy requests to a Thin backend.

then start your Thin cluster like this:

thin start -s3 -p 5000

You can also setup a Thin config file and use it to control your cluster:

thin config -C myapp.yml -s3 -p 5000
thin start -C myapp.yml

To connect to Nginx using UNIX domain sockets edit the upstream block in your nginx config file:

nginx.conf
upstream  backend {
   server   unix:/tmp/thin.0.sock;
   server   unix:/tmp/thin.1.sock;
   server   unix:/tmp/thin.2.sock;
}

and start your cluster like this:

thin start -s3 --socket /tmp/thin.sock