What
Thin is a Ruby web server that glues together 3 of the best Ruby libraries in web history:
- the Mongrel parser, the root of Mongrel speed and security
- Event Machine, a network I/O library with extremely high scalability, performance and stability
- Rack, a minimal interface between webservers and Ruby frameworks
Which makes it, with all humility, the most secure, stable, fast and extensible Ruby web server bundled in an easy to use gem for your own pleasure.
Installation & Usage
Minimum Requirements include either Ruby 1.86 or 1.9. Love that last bit about 1.9.
sudo gem install thin
Using with Rails
After installing the Gem, a thin
script should be in your path to easily start your Rails application.
cd to/your/rails/app thin start 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!
test.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 test.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 -------------- Quoted from code.macournoyer.com