Nov 8 2007

Send it to Obedience School

I have a little rails app that can have a lot of
images on each page. It worked fine in development, but when I went to deploy
it with mongrel behind apache’s mod_proxy, it started behaving oddly. It would
randomly and inexplicably not serve up thumbnails. I checked all my code, the
thumbnails were being generated properly, and my code checked out. Apache would
complain with something like this:

[error] proxy: error reading status line from remote server 127.0.0.1, referer: http://foton.fugal.net/album/detail/23
[error] proxy: Error reading from remote server returned by /foto/thumbnail/93, referer: http://foton.fugal.net/album/detail/23

Carefully watching my rails logs, I noticed they weren’t mentioning the
offending files (that Apache was complaining about), so I guessed the problem
must be between Apache and my code, i.e. in Mongrel. So I fired it up with
Lighttpd instead of Mongrel, and lo and behold it worked fine. To be fair, I
didn’t try upgrading Mongrel (from 1.0.1 to whatever’s current—1.1 I think).
Maybe this is a fixed bug. But now you know it’s Mongrel’s fault, if you’re
seeing something similar.


Apr 1 2006

Typo

I am in the process of migrating my blog to Typo. Blosxom has served me well, but I think it’s time I joined the ranks of cool blogs and allowed people to comment, trackback, etc. Blosxom can do all that, but it’s not very much fun.

Blosxom’s strength is its simplicity. When I wanted a simple blog, it was perfect.

Now, getting typo to work was not a walk in the park. I’ll walk you through what I had to do.

First, you have to get typo and install it. I hear rumors that version 4 release is imminent, so I grabbed the svn version. Next, make a database and set up config/database.yml. Now you can run script/server -e production and point your browser at http://localhost:3000/ and give it a whirl.

I tried the RSS and atom converters in db/converters but I wasn’t satisfied with the results. So I wrote a blosxom converter, which I will contribute. If you can’t find it feel free to contact me.

The hard part was getting typo to run under a subdirectory in my mixed apache/lighttpd setup. All fugal.net sites are running through Apache. My rails apps run through lighttpd, with apache’s mod_proxy. So, you have to configure apache, lighttpd, and rails each in turn.

Apache Configuration

    ProxyPass               /typo http://127.0.0.1:81/typo
    ProxyPassReverse        /typo http://127.0.0.1:81/typo
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>

Lighttpd Configuration

The normal lighttpd stuff, and then:

$HTTP["url"] =~ "^/typo(/|$)" {
    server.indexfiles = ("dispatch.fcgi")
    server.document-root = "/srv/www/typo/public/"
    server.error-handler-404 = "/dispatch.fcgi"
    server.errorlog = "/srv/www/typo/log/error.log"
    accesslog.filename = "/srv/www/typo/log/access.log"
    fastcgi.server = ( ".fcgi" => (
        "typo" => ( "min-procs" => 1, "max-procs" => 1,
            "socket" => "/tmp/typo.fcgi.socket",
            "bin-path" => "/srv/www/typo/public/dispatch.fcgi",
            "bin-environment" => ( "RAILS_ENV" => "production" ),
            "idle-timeout" => 120
            )
        )
    )
}

You don’t need strip-request-uri, because we’ll take care of the typo/ prefix in rails.

Rails Config

Add this to config/environment.rb:

    ActionController::AbstractRequest.relative_url_root = "/typo"

Finally, and this was the real stink, you have to help lighttpd find files in public/. Lighttpd gets a request for http://hans.fugal.net/typo/foo.html which is a static file in public/, and so it looks in the document root to find /typo/foo.html, which means it looks for /srv/www/typo/public/typo/foo.html, which doesn’t exist. This is easy to fix:

    cd /srv/www/typo/public
    ln -s . typo

et voilá! You should be up and running.

For more reading see http://znark.com/blog/articles/2005/12/11/got-typo-working and http://blog.lighttpd.net/articles/2005/11/23/lighttpd-1-4-8-and-multiple-rails-apps.