Julius Plenz – Blog

software design

I'm in the process of setting up a new server. I struggled for some minutes now with the follwing strange behaviour: Lighttpd is very picky (and not at all verbose) about when you use alias.url.

As an actual example, look at these two blocks:

$HTTP["host"] == "HOST" {
  alias.url += ("/munin" => "/var/www/munin")
}

$SERVER["socket"] == ":443" {
  $HTTP["host"] == "HOST" {
    alias.url += ("/wiki" => "/usr/share/dokuwiki",)
  }
}

Now I, the innocent user, would expect the following to happen:

But, alas, nope. It's quite different. The wiki is available alright if called before the munin part, and vice versa. The other one will be a 404, though. To make things work I actually have to double the alias part for munin – once outside the part that matches for SSL and once inside.

Oh, and don't confuse == and =~ – even if both match, the exact match wins. (Meaning you cannot put the line in a condition like =~ ":(443|80)".) So there's no real cascading or so. Bad design in my opinion, but it seems to be intentional. WTF?

Correct solution:

$HTTP["host"] == "HOST" {
  alias.url += ("/munin" => "/var/www/munin")
}

$SERVER["socket"] == ":443" {
  $HTTP["host"] == "HOST" {
    alias.url += ("/munin" => "/var/www/munin")
  }
}

$SERVER["socket"] == ":443" {
  $HTTP["host"] == "HOST" {
    alias.url += ("/wiki" => "/usr/share/dokuwiki",)
  }
}

Holy crap. Explain that to someone unfamiliar with how difficult it is to implement data structures in C. – They'd just call you a moron for not implementing a more intuitive aproach. – Wait, I do, too!

posted 2011-09-21 tagged lighttpd and rant