Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

103 lines (77 sloc) 2.387 kB

Lighttpd Proxied to Thin

This will cover how to deploy Sinatra to a load balanced reverse proxy setup using Lighttpd and Thin.

Install Lighttpd and Thin

# Figure out lighttpd yourself, it should be handled by your
# linux distro's package manager

# For thin:
gem install thin

Create your rackup file

The require 'app' line should require the actual Sinatra app you have written.

## This is not needed for Thin > 1.0.0
ENV['RACK_ENV'] = "production"

require File.expand_path '../app.rb', __FILE__

run Sinatra::Application

Setup a config.yml

Change the /path/to/my/app path to reflect reality.

 environment: production
 chdir: /path/to/my/app
 user: root
 group: root
 port: 4567
 pid: /path/to/my/app/
 rackup: /path/to/my/app/
 log: /path/to/my/app/thin.log
 max_conns: 1024
 timeout: 30
 max_persistent_conns: 512
 daemonize: true

Setup lighttpd.conf

Change mydomain to reflect reality. Also make sure the first port here matches up with the port setting in config.yml.

$HTTP["host"] =~ "(www\.)?mydomain\.com"  {
 proxy.balance = "fair"
 proxy.server =  ("/" =>
                     ( "host" => "", "port" => 4567 ),
                     ( "host" => "", "port" => 4568 )

Start thin and your application.

I have a rake script so I can just call "rake start" rather than typing this in.

thin -s 2 -C config.yml -R start

You're done! Go to and see the result! Everything should be setup now, check it out at the domain you setup in your lighttpd.conf file.

Variation - nginx via proxy - The same approach to proxying can be applied to the nginx web server

upstream www_mydomain_com {

server {
  server_name live;
  access_log /path/to/logfile.log;

  location / {
    proxy_pass http://www_mydomain_com;


Variation - More Thin instances - To add more thin instances, change the -s 2 parameter on the thin start command to be how ever many servers you want. Then be sure lighttpd proxies to all of them by adding more lines to the proxy statements. Then restart lighttpd and everything should come up as expected.

Jump to Line
Something went wrong with that request. Please try again.