Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

running multiple domains off a single rails app with different page caching directories (See related posts)

Problem: You have multiple instances of a rails app that use page caching, but you'd rather not set up a separate instance for each one.

Lighttpd config:
#... normal lighty conf...
server.document-root = "/home/rails/app/public/"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = (
  ".fcgi" =>
    ("localhost" =>
      (
       "min-procs" => 1,
       "max-procs" => 1,
       "socket" => "/tmp/rails-fcgi1.socket",
       "bin-path" => "/home/rails/app/public/dispatch.fcgi",
       "bin-environment" => (
         "RAILS_ENV" => "production",
         "TZ"        => "America/Chicago"
       )
     )
    )
 )

$HTTP["host"] =~ "site1.net" {
  server.document-root = "/home/rails/app/public/site1.net"
}
$HTTP["host"] =~ "site2.net" {
  server.document-root = "/home/rails/app/public/site2.net"
}


Rails code to set the page cache directory:

before_filter { |c| c.class.page_cache_directory = "#{RAILS_ROOT}/public/#{c.request.host}" }


Remember to symlink your necessary files AND your dispatch.fcgi to each page cache directory.

Comments on this post

orangechicken posts on Nov 20, 2006 at 02:42
Could you do this without doing all the symlinking (and multiple $HTTP[host] entries) by adding a simple rule to check if the file with the current host prepended exists and if not just send to the app? (I realize this is over a year later posting to this).

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts