Well, it was a pain in the ass, but I managed to get multiple Rails sites running with lighttpd on the same domain.

Here’s the interesting parts of the lighttpd.conf file that makes this magic shit work:

# needed for aliases to work
server.modules = ( "mod_rewrite", "mod_fastcgi", "mod_alias" )

$HTTP["url"] =~ "^/svn_browser/cisv" {
  server.document-root = "/users/home/joevd/domains/joevandyk.com/cisv_collaboa/public/" 
  alias.url = ( "/svn_browser/cisv" => "/users/home/joevd/domains/joevandyk.com/cisv_collaboa/public" )
  server.error-handler-404 = "/svn_browser/cisv/dispatch.fcgi" 
  server.indexfiles = ( "dispatch.fcgi", "index.html" )

  fastcgi.server = ( ".fcgi" =>
    (( 
       "socket" => "/home/joevd/lighttpd/joevd_cisv_svn1.socket",
       "min-procs" => 1,
       "max-procs" => 1,
       "bin-path" =>  "/users/home/joevd/domains/joevandyk.com/cisv_collaboa/public/dispatch.fcgi",
       "bin-environment" => ( "RAILS_ENV" => "production" )
  )))
}

$HTTP["url"] =~ "^/svn_browser/gamefest" {
  server.document-root = "/users/home/joevd/domains/joevandyk.com/gamefest_collaboa/public/" 
  alias.url = ( "/svn_browser/gamefest" => "/users/home/joevd/domains/joevandyk.com/gamefest_collaboa/public" )
  server.error-handler-404 = "/svn_browser/gamefest/dispatch.fcgi" 
  server.indexfiles = ( "dispatch.fcgi", "index.html" )

  fastcgi.server = ( ".fcgi" =>
    (( 
       "socket" => "/home/joevd/lighttpd/joevd_gamefest_svn1.socket",
       "min-procs" => 1,
       "max-procs" => 1,
       "bin-path" =>  "/users/home/joevd/domains/joevandyk.com/gamefest_collaboa/public/dispatch.fcgi",
       "bin-environment" => ( "RAILS_ENV" => "production" )
  )))
}
You also need to add the following to the app’s config/environment.rb file (at the very end):
ActionController::AbstractRequest.relative_url_root = "/svn_browser/cisv" 

It’s a royal pain, but it’s pretty cool once you got a working configuration.

10 Responses to “Getting multiple Rails sites going on one domain using lighttpd”

  1. bill Says:

    That is pretty neat. Looks awfully complicated though.

  2. Joe Says:

    Yeah, lighttpd config files are ugly, imo. But they’re really powerful and flexible. And it’s a hella fast server.

  3. Arun Says:
    Sigh! I wish I had found this article first instead of this thread: on textdrive I tried out all the configurations in the other thread with no luck until I figured out this configuration that’s listed here.

    For me the critical thing that I was missing was:
    1. ActionController::AbstractRequest.relative_url_root = ”/svn_browser/cisv”
    2. and: not including “strip-request-uri” => ”/contacts”
  4. Joe Says:

    Glad it helped someone!

  5. Louis Says:

    This is awesome!!! THANK YOU!!!!!!

    I tinkered with these: http://blog.lighttpd.net/articles/2005/11/23/lighttpd-1-4-8-and-multiple-rails-apps http://serbiancafe.wordpress.com/2005/12/05/lighttpd-configuration-files-for-multiple-rails-apps/

    And then I went onto technorati and found your site and after a bit of tweaking it worked!

    Thank you.

  6. Deirdre Saoirse Moen Says:

    Thanks—my config I’d posted on the TxD forums broke with lighttpd 1.4.9, and this helped me tweak it back to health.

  7. Bart Braem Says:

    Does this work with static files too? And with index.html? I can’t get it working here when using an Apache reverse proxy that redirects to localhost (without stripping of urls)

  8. Ben Kittrell Says:

    Yes Yes, thank you very much. I have been searching for this, and it actually works!

    Rock on!

  9. Add this to the Rails Wiki Says:

    You should add this to the Rails Wiki in the HowtosDeployment section. It’s taken days for me to write the proper google query to find information that works.

  10. Joe Says:

    Hm… yeah, I should probably publish this somewhere. Good thinking.

Sorry, comments are closed for this article.