Running Multiple Domains Off A Single Rails App With Different Page Caching Directories
Join the DZone community and get the full member experience.
Join For FreeProblem: 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.
app
Opinions expressed by DZone contributors are their own.
Comments