Forum: Ruby on Rails Multiple Rails app on the same server?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Vince W. (Guest)
on 2006-02-16 02:17
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.

[code]
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"
)
[/code]
Vince W. (Guest)
on 2006-02-16 18:26
anyone?
Ezra Z. (Guest)
on 2006-02-16 20:02
(Received via mailing list)
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
Vince W. (Guest)
on 2006-02-16 20:29
>
> 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
Neil D. (Guest)
on 2006-02-17 00:50
(Received via mailing list)
Vince W. wrote:
> anyone?
>
I have two different RoR apps & two ordinary web-sites on the one
lighttpd server.
Works no problem :)

Plus two encrypted sites (one RoR) on another lighttpd server.
Vince W. (Guest)
on 2006-02-17 01:17
Neil D. wrote:

> I have two different RoR apps & two ordinary web-sites on the one
> lighttpd server.
> Works no problem :)
>
> 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
Peter (Guest)
on 2006-02-17 02:05
>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.
Stephen V. (Guest)
on 2006-02-17 02:12
(Received via mailing list)
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.
Vince W. (Guest)
on 2006-02-17 04:52
> 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/light...

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

[code]
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..
)
[/code]
Neil D. (Guest)
on 2006-02-17 05:01
(Received via mailing list)
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://<app>.<domain>
Michael T. (Guest)
on 2006-02-17 05:10
(Received via mailing list)
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" )
      )
    )
  )
}
Stephen V. (Guest)
on 2006-02-17 22:48
(Received via mailing list)
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.
This topic is locked and can not be replied to.