Multiple Rails app on the same server?


#1

I have a rails app on a debian server running lighttpd and I’m trying to
set up typo so that it also works (with a different url). I have 4 URLs
running – let’s call them foo.com, bar.com, www.typo.com and
php.typo.com

I am starting lighttpd by going into the directory where my foo.com app
is and typing either ruby script/server or script/server -e production
– either way the results I get are:

foo.com works (rails app)
bar.com works (non rails app … just html but will have a rails app
later)
php.typo.com works (phpmyadmin for mysql)
www.typo.com shows me foo.com with broken images instead of typo

Not sure why that’s happening… can somebody help? I am posting my
lighttpd.conf file but I’m not sure if this is where my error is. FWIW
I have already set up a database called typo using php.typo.com.

server.modules              = (
                                "mod_rewrite",
                                "mod_redirect",
                                "mod_proxy",
                                "mod_accesslog",
                                "mod_access",
                                "mod_fastcgi",
                                "mod_compress",
                                "mod_accesslog" )
server.document-root       = "/var/www"
server.bind                = "0.0.0.0"
server.port                = 80
server.pid-file            = "/var/run/lighttpd.pid"
server.tag                 = "lighttpd"
accesslog.filename         = "/var/log/lighttpd.access.log"
server.errorlog            = "/var/log/lighttpd.error.log"
server.indexfiles          = ( "index.php", "index.html", "index.htm", 
"default.
htm" )
url.access-deny            = ( "~", ".inc" )

$HTTP["host"] == "php.typo.com" {
     accesslog.filename         = "/var/log/lighttpd.php.access.log"
     server.document-root     = "/var/www/phpmyadmin"
     server.indexfiles          = ( "index.php", "index.html", 
"index.htm", "def
ault.htm" )
       fastcgi.server = (
          ".php" =>
              ( "localhost" =>
               (
                "socket" => "/tmp/php4-fcgi.socket",
                "bin-path" => "/usr/bin/php4-cgi -c 
/etc/php4/cgi/php.ini",
                       "bin-environment" => (
                       "PHP_FCGI_CHILDREN" => "32",
                       "PHP_FCGI_MAX_REQUESTS" => "5000"
                                             )
               )
              )
                        )
}
# Rails site, I want this on www or no www
$HTTP["host"] == "www.bar.com" {
  server.port                = 80
  server.document-root     = "/var/www/bar/public"
  server.error-handler-404 = "/dispatch.fcgi"
  server.indexfiles          = ( "index.php", "index.html", "index.htm", 
"defaul
t.htm" )
  url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )
  fastcgi.server =  (
     ".fcgi" => (
       "localhost" => (
         "socket" => "log/fcgi.socket",
         "bin-environment" => ( "RAILS_ENV" => "development" ),
         "bin-path" => "public/dispatch.fcgi",
#         "max-load-per-proc" => 4,
         "min-procs" => 1,
         "max-procs" => 4,
#         "idle-timeout" => 60
     )
    )
  )
}

# Railfood vhost
$HTTP["host"] == "www.foo.com" {
  server.port                = 80
  server.document-root     = "/var/www/foo/public"
  server.error-handler-404 = "/dispatch.fcgi"
  server.indexfiles          = ( "index.php", "index.html", "index.htm", 
"defaul
t.htm" )
  url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )
  fastcgi.server =  (
     ".fcgi" => (
       "localhost" => (
         "socket" => "log/fcgi.socket",
         "bin-environment" => ( "RAILS_ENV" => "development" ),
         "bin-path" => "public/dispatch.fcgi",
#         "max-load-per-proc" => 4,
         "min-procs" => 1,
         "max-procs" => 4
#         "idle-timeout" => 60
     )
    )
  )
}
$HTTP["host"] == "www.typo.com" {
  server.port                = 80
  server.document-root     = "/var/www/typo/public"
  server.error-handler-404 = "/dispatch.fcgi"
  server.indexfiles          = ( "index.php", "index.html", "index.htm", 
"defaul
t.htm" )
  url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" )
  fastcgi.server =  (
     ".fcgi" => (
       "localhost" => (
         "socket" => "log/fcgi.socket",
         "bin-environment" => ( "RAILS_ENV" => "production" ),
         "bin-path" => "public/dispatch.fcgi",
#         "max-load-per-proc" => 4,
         "min-procs" => 1,
         "max-procs" => 4
#         "idle-timeout" => 60
     )
    )
  )
}
mimetype.assign = (
  ".pdf"        =>      "application/pdf",
  ".css"        =>      "text/css",
  ".gif"        =>      "image/gif",
  ".htm"        =>      "text/html",
  ".html"       =>      "text/html",
  ".jpeg"       =>      "image/jpeg",
  ".jpg"        =>      "image/jpeg",
  ".js"         =>      "text/javascript",
  ".png"        =>      "image/png",
  ".sig"        =>    "application/pgp-signature",
  ".spl"        =>      "application/futuresplash",
  ".class"      =>      "application/octet-stream",
  ".ps"           =>      "application/postscript",
  ".torrent"      =>      "application/x-bittorrent",
  ".dvi"          =>      "application/x-dvi",
  ".gz"           =>      "application/x-gzip",
  ".pac"          =>      "application/x-ns-proxy-autoconfig",
  ".swf"          =>      "application/x-shockwave-flash",
  ".txt"          =>      "text/plain"
)

#2

anyone?


#3

On Feb 16, 2006, at 8:26 AM, Vince W. wrote:

anyone?


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Vince-

I am reading this from the mailing list so i don't see your initial

question. What platform is the server and what webserver are you
using? Lighttpd or apache? I’ll give you my configs if you explain
your details a bit more.

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#4

Vince W. wrote:

anyone?

I have two different RoR apps & two ordinary web-sites on the one
lighttpd server.
Works no problem :slight_smile:

Plus two encrypted sites (one RoR) on another lighttpd server.


#5

Neil D. wrote:

I have two different RoR apps & two ordinary web-sites on the one
lighttpd server.
Works no problem :slight_smile:

Plus two encrypted sites (one RoR) on another lighttpd server.

Yep, got this working with Ezra’s help. Will post the solution if
anyone is interested but it boiled down to some corrections in
lighttpd.conf


#6

if anyone is interested

I am working on one app right now so at the moment it isn’t important.
But in the future it will and probably for many others.

So please share.


#7

On 2/16/06, Peter removed_email_address@domain.invalid wrote:

if anyone is interested

I am working on one app right now so at the moment it isn’t important.
But in the future it will and probably for many others.

So please share.

I am also interested in this solution. I need to run two applications
on the same port with the same domain name.


#8

Vince-

I am reading this from the mailing list so i don’t see your initial
question. What platform is the server and what webserver are you
using? Lighttpd or apache? I’ll give you my configs if you explain
your details a bit more.

Hi Ezra,
I replied to you by email and will post a solution back to the board
once it’s solved. Thanks for your help!
Vince


#9

I am also interested in this solution. I need to run two applications
on the same port with the same domain name.

This is actually to run two apps on two domains on the same machine. I
suppose this could be modified for your purposes but you could also look
at the solution here:

http://blog.lighttpd.net/articles/2005/11/23/lighttpd-1-4-8-and-multiple-rails-apps

Anyway, here is the lighttpd.conf file that Ezra so graciously helped me
with:

server.modules          = (
                        "mod_rewrite",
                        "mod_redirect",
                        "mod_access",
                        "mod_fastcgi",
                        "mod_compress",
                        "mod_accesslog")

server.document-root    = "/var/www"
server.bind             = "0.0.0.0"
server.port             = 80
server.pid-file         = "/tmp/main_lighttpd.pid"
server.tag              = "lighttpd"
accesslog.filename      = "/var/log/lighttpd.access.log"
server.errorlog         = "/var/log/lighttpd.error.log"
server.indexfiles       = 
("index.php","index.html","index.htm","default.htm")
#url.access-deny                = ("~", ".inc")

$HTTP["host"] =~ "(^|\.)foo.com" {
server.document-root = "/var/www/foo/public/"
server.error-handler-404 = "/dispatch.fcgi"
server.indexfiles = ("dispatch.fcgi")
 fastcgi.server = (".fcgi" =>
   ("localhost" =>
      ("socket" => "/tmp/foo.socket",
                   "min-procs" => 2,
                   "max-procs" => 2,
        "bin-path" => "/var/www/foo/public/dispatch.fcgi",
        "bin-environment" => ("RAILS_ENV" => "development")
  )))
}

$HTTP["host"] =~ "(^|\.)typo\.com" {
server.document-root = "/var/www/typo/public/"
server.error-handler-404 = "/dispatch.fcgi"
server.indexfiles = ("dispatch.fcgi")
  fastcgi.server = (".fcgi" =>
    ("localhost" =>
        ("socket" => "/tmp/typo.socket",
                     "min-procs" => 2,
                     "max-procs" => 2,
        "bin-path" => "/var/www/typo/public/dispatch.fcgi",
        "bin-environment" => ("RAILS_ENV" => "production")
  )))
}

mimetype.assign = (
".pdf"          =>      "application/pdf",
  ".sig"          =>      "application/pgp-signature",
  ".spl"          =>      "application/futuresplash",

snip..
)

#10

Vince W. wrote:

I am also interested in this solution. I need to run two applications
on the same port with the same domain name.

How where you thinking of deciding on what app to run?

I use subdomains like http://.


#11

I am doing just that. The following shows two separate apps as
subdirectories off of a single domain and then another one that’s a
subdomain so you can see how it all works. I’ve not included all the
other stuff, just the pertinent parts. I also had to add the
following line into my production.rb file in the config/environments
directory for each app:

ActionController::AbstractRequest.relative_url_root = “/app1”

$HTTP[“host”] == “www.railsconsulting.com” {
$HTTP[“url”] =~ “^/app1” {
var.appname = “app1”
server.document-root = “/var/www/” + var.appname +
“/current/public”
alias.url = ( “/app1” => “/var/www/” + var.appname +
“/current/public” )
server.error-handler-404 = “/app1/dispatch.fcgi”
fastcgi.server = ( “.fcgi” =>
( var.appname =>
( “min-procs” => 2,
“max-procs” => 2,
“socket” => “/tmp/” + var.appname + “.fcgi.socket”,
“bin-path” => “/var/www/” + var.appname +
“/current/public/dispatch.fc
gi”,
“bin-environment” => ( “RAILS_ENV” => “production” ),
)
)
)
}
$HTTP[“url”] =~ “^/app2” {
var.appname = “app2”
server.document-root = “/var/www/” + var.appname +
“/current/public”
alias.url = ( “/app2” => “/var/www/” + var.appname +
“/current/public” )
server.error-handler-404 = “/app2/dispatch.fcgi”
fastcgi.server = ( “.fcgi” =>
( var.appname =>
( “min-procs” => 2,
“max-procs” => 2,
“socket” => “/tmp/” + var.appname + “.fcgi.socket”,
“bin-path” => “/var/www/” + var.appname +
“/current/public/dispatch.fc
gi”,
“bin-environment” => ( “RAILS_ENV” => “production” ),
)
)
)
}
}

BLOG

$HTTP[“host”] == “blog.railsconsulting.com” {
var.appname = “typo”
server.document-root = “/var/www/” + var.appname + “/public”
fastcgi.server = ( “.fcgi” =>
( var.appname =>
( “min-procs” => 2,
“max-procs” => 2,
“socket” => “/tmp/” + var.appname + “.fcgi.socket”,
“bin-path” => “/var/www/” + var.appname +
“/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)
)
)
}


#12

On 2/16/06, Michael T. removed_email_address@domain.invalid wrote:

$HTTP[“host”] == “www.railsconsulting.com” {
“bin-path” => “/var/www/” + var.appname + "/current/public/dispatch.fc
server.error-handler-404 = “/app2/dispatch.fcgi”
)
“max-procs” => 2,
“socket” => “/tmp/” + var.appname + “.fcgi.socket”,
“bin-path” => “/var/www/” + var.appname + “/public/dispatch.fcgi”,
“bin-environment” => ( “RAILS_ENV” => “production” )
)
)
)
}

Thanks! I missed the $HTTP[“url”] conditional.