lighttpd 1.4.8 supports multiple rails aps via ’strip-request-uri’. Lighty guys wrote about it here.
’strip-request-uri’ strips URI’s from returning html, which is great if you’re proxying your application through another server. In my case I run apache as a primary server. All my Ruby on rails applications are on lighttpd running on the same server, but higher port, 8888.
One of the domains on the primary server, metak.com, runs my ajaxed Serbian..English dictionary application. For usability purposes I want this domain to operate in “/”, but my true location on lighty server is “/lat/recnik/”. ’strip-request-uri’ does exactly what’s needed to fix this. Not just that it allows you to have multiple apps, but it gets rid of this “/lat/recnik/” path from resulting html.
Another way of getting multiple apps to work was brought up in the comments of lighty’s post. It works by adding code in rails environment.rb file:
ActionController::AbstractRequest.relative_url_root = “/lat/recnik”
This sure works, but the resulting html includes absolute uri’s “/lat/recnik/….”, so when you access it through the proxy it points to “/lat/recnik” directory which doesn’t exist on the primary server.
This method sure works better if you’re running lighty as a primary server :)
Finally, here’s my config file:
# lighttpd configuration file
#
# use a it as base for lighttpd 1.0.0 and above
#
# $Id: lighttpd.conf,v 1.7 2004/11/03 22:26:05 weigon Exp $
############ Options you really have to take care of ####################
## modules to load
server.modules = ("mod_rewrite", "mod_alias", "mod_access", "mod_status", "mod_fastcgi", "mod_accesslog" )
## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root = "/www/site/"
## where to send error-messages to
server.errorlog = "/www/log/error.log"
# files to check for if .../ is requested
index-file.names = ( "index.html", "index.htm", "default.htm" )
# mimetype mapping
mimetype.assign = (
".pdf" => "application/pdf",
[.... lots of boring lines here. Copy them from your original config file! ]
".tar.bz2" => "application/x-bzip-compressed-tar"
)
## be nice and keep it at lighttpd
server.tag = "lighttpd | SerbianCafe"
#### accesslog module
accesslog.filename = "/www/log/access.log"
## deny access the file-extensions
url.access-deny = ( "~", ".inc" )
$HTTP["url"] =~ ".pdf$" {
server.range-requests = "disable"
}
# which extensions should not be handle via static-file transfer
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
######### Options that are good to be but not neccesary to be changed #######
## bind to port (default: 80)
# Use high ports unless you want to run the web server as root
server.port = 8888
## bind to localhost (default: all interfaces)
#server.bind = "serbiancafe.com"
## to help the rc.scripts
server.pid-file = "/www/run/lighttpd.pid"
#### status module
status.status-url = "/server-status"
$HTTP["url"] =~ "^/lat/recnik/" {
server.document-root = "/www/site/lat/recnik/public/"
alias.url = ( "/lat/recnik/" => "/www/site/lat/recnik/public/" )
server.error-handler-404 = "/lat/recnik/dispatch.fcgi"
fastcgi.server = ( "/lat/recnik/dispatch.fcgi" =>
(( "socket" => "/www/tmp/recnik.socket" ,
"bin-path" => "/www/site/lat/recnik/public/dispatch.fcgi",
"bin-environment" => ( "RAILS_ENV" => "development" ),
"strip-request-uri" => "/lat/recnik"
)))
}
$HTTP["url"] =~ "^/typo/" {
server.document-root = "/www/railsapps/typo/public/"
alias.url = ( "/typo/" => "/www/railsapps/typo/public/" )
server.error-handler-404 = "/typo/dispatch.fcgi"
fastcgi.server = ( "/typo/dispatch.fcgi" =>
(( "socket" => "/www/tmp/typo.socket" ,
"bin-path" => "/www/railsapps/typo/public/dispatch.fcgi",
"bin-environment" => ( "RAILS_ENV" => "development" ),
"strip-request-uri" => "/typo"
)))
}
### only root can use these options
#
# chroot() to directory (default: no chroot() )
#server.chroot = "/"
## change uid to (default: don't care)
server.username = "wwwrun"
## change uid to (default: don't care)
server.groupname = "wwwrun"
#### compress module
#compress.cache-dir = "/tmp/lighttpd/cache/compress/"
#compress.filetype = ("text/plain", "text/html")
freebsd + lighttpd + Typo^H^H^H^HWordPress said
[...] First were my problems with lighttpd.conf and trying to get rails working with directory aliasing. After looking in a few places (here and here), thanks to technorati I finally found something else here that worked. [...]
Ryan said
This get’s me to being able to access my static index.html in my app’s public directory, but I just get 404 when I try to reacha controller.
Joe’s Amazing Technicolor Weblog » Blog Archive » Deploying my first rails app said
[...] to this lighttpd configuration guide for pointing out that alias.url needs to be set as well for the public/ directory to be properly [...]
greenpossum said
Thanks for this tip.
But I found that I had to use the $HTTP["host"] matching against the virtual host name instead of $HTTP["url'] matching against the first part of the path to make it work. Otherwise I got a 404 like Ryan did. Looking at the logs, it seems that aside from the top page, and maybe static pages (I don’t know), the other requests went to the main host, not the virtual host. The condition log showed some requests for dispatch.cgi which were not matched by the virtual host.
I don’t know if the lighttpd version has anything to do with it, I’m running 1.4.20. I could have sworn it was working with “url” before a recent update.
If you use “host” matching, then be sure to specify “ProxyPreserveHost on” on the Apache side, otherwise lighttpd doesn’t get the original Host: header.