Trac at site root with lighttpd 1.5.0
For a long time I have been trying to set up trac to work as site root.
Consider a website http://trac.site.com/, I would like to have URL
http://trac.site.com/ point to default page (usually the wiki page
also served as http://trac.site.com/wiki), URL
http://trac.site.com/timeline point to the timeline page,
URL http://trac.site.com/roadmap point to the roadmap page, etc.
At no point should trac rewrite the URLs to anything
like http://trac.site.com/trac/timeline.
Such setup is possible with an apache webserver, but has been extremely
difficult to get working with lighttpd. Fortunately, it is possible with
lighty version 1.5.0. Here is the configuration of a working setup featuring
lighttpd 1.5.0 Subversion snapshot of revision 1900 and trac 0.10.4.
Since it is lighttpd version 1.5.0, we use the new mod_proxy_core module
to communicate with the trac FastCGI process spawned externally using
the spawn-fcgi utility and listening for connections on localhost port
9000.
The layout of /var/www/trac.site.com/ directory is as follows:
/var/www/trac.site.com/
|-- ...
`-- htdocs
|-- site-icon.ico
|-- site-logo.png
|-- ...
`-- trac
`-- ...
I want to serve static content from /var/www/trac.site.com/htdocs and
trac static content from /var/www/trac.site.com/htdocs/trac. Static
content includes website icon, website logo and whatever else I will manually
upload in the future. Trac static content is the files provided by a trac
installation and otherwise requested from .../chrome/common/.
This requires some modifications to the ini-file of the trac project.
My trac.ini has the following things set:
[header_logo] src = /htdocs/site-logo.png ... [project] icon = /htdocs/site-icon.ico [trac] htdocs_location = /htdocs/trac/ ...
Note: if you don’t set htdocs_location above, static trac content
will be requested from /chrome/common/ directory instead. In this
case, lighttpd will not handle the request itself, but will forward it
to trac. This will not break anything, as trac will serve it’s static
content without a glitch, but it may be slower in doing so than lighttpd.
The lighttpd configuration file looks like:
server.modules = ( "mod_alias",
"mod_auth",
"mod_proxy_code",
"mod_proxy_backend_fastcgi",
...
)
...
$HTTP["host"] == "trac.site.com" {
# trac-based website
# static content root
alias.url = ( "/htdocs/" => "/var/www/trac.site.com/htdocs/" )
# authentication settings
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = "/var/trac/trac.htpasswd"
$HTTP["url"] =~ "^/htdocs/" {
# static concent
}
else $HTTP["url"] =~ "^/login$" {
# login handling
auth.require = ( "/" => ( "method" => "basic",
"realm" => "site.com trac website",
"require" => "valid-user"
)
)
}
$HTTP["url"] !~ "^/htdocs" {
# trac via fastcgi
proxy-core.protocol = "fastcgi"
proxy-core.backends = ( "127.0.0.1:9000" )
proxy-core.rewrite-request = ( "_pathinfo" => ( "^(/.*)" => "$1" ),
"_scriptname" => ( "" => "/" )
)
}
}
...
The rewrite-request part doesn’t make sense, but it is the black magic
that makes it actually work.
I’m sure there are better ways of achieving the same behavior. If you
got the same result with lighttpd 1.5.0 with less hassle, I would like
to hear from you.
| Posted in blog | No Comments »